classSolution:deflongestMountain(self,A: List[int]) ->int: n =len(A) maxL =0for i inrange(n): length =0#山脉长度#找到山顶if i-1>=0and i+1< n and A[i]> A[i-1]and A[i]> A[i+1]: length +=1 left = right = i #山顶左右两侧指针while left-1>=0and A[left]> A[left-1]: left -=1 length +=1while right+1< n and A[right]> A[right+1]: right +=1 length +=1 maxL =max(length, maxL)return maxL