@@ -0,0 +1,1302 @@
+# Time:  O(n)%0A# Space: O(1)%0A%0A# Let's call any (contiguous) subarray B (of A) a mountain%0A# if the following properties hold:%0A#%0A# B.length %3E= 3%0A# There exists some 0 %3C i %3C B.length - 1%0A# such that B%5B0%5D %3C B%5B1%5D %3C ... B%5Bi-1%5D %3C B%5Bi%5D %3E B%5Bi+1%5D %3E ... %3E B%5BB.length - 1%5D%0A# (Note that B could be any subarray of A, including the entire array A.)%0A#%0A# Given an array A of integers, return the length of the longest mountain.%0A#%0A# Return 0 if there is no mountain.%0A#%0A# Example 1:%0A#%0A# Input: %5B2,1,4,7,3,2,5%5D%0A# Output: 5%0A# Explanation: The largest mountain is %5B1,4,7,3,2%5D which has length 5.%0A# Example 2:%0A#%0A# Input: %5B2,2,2%5D%0A# Output: 0%0A# Explanation: There is no mountain.%0A#%0A# Note:%0A# - 0 %3C= A.length %3C= 10000%0A# - 0 %3C= A%5Bi%5D %3C= 10000%0A%0Atry:%0A    xrange          # Python 2%0Aexcept NameError:%0A    xrange = range  # Python 3%0A%0A%0Aclass Solution(object):%0A    def longestMountain(self, A):%0A        %22%22%22%0A        :type A: List%5Bint%5D%0A        :rtype: int%0A        %22%22%22%0A        result, up_len, down_len = 0, 0, 0%0A        for i in xrange(1, len(A)):%0A            if (down_len and A%5Bi-1%5D %3C A%5Bi%5D) or A%5Bi-1%5D == A%5Bi%5D:%0A                up_len, down_len = 0, 0%0A            up_len += A%5Bi-1%5D %3C A%5Bi%5D%0A            down_len += A%5Bi-1%5D %3E A%5Bi%5D%0A            if up_len and down_len:%0A                result = max(result, up_len+down_len+1)%0A        return result%0A

Create longest-mountain-in-array.py