标签:range max else span long style 初始化 for 遍历
1 class Solution: 2 def longestMountain(self, A: List[int]) -> int: 3 n = len(A) 4 left = [0] * n # 初始化 5 for i in range(1, n): 6 left[i] = (left[i - 1] + 1 if A[i - 1] < A[i] else 0) 7 8 right = [0] * n 9 for i in range(n - 2, -1, -1): # 倒着遍历的 10 right[i] = (right[i + 1] + 1 if A[i] > A[i + 1] else 0) 11 12 ans = 0 13 for i in range(n): 14 if left[i] > 0 and right[i] > 0: 15 ans = max(ans, left[i] + right[i] + 1) 16 17 return ans
水平不行,但是官方题解很不错 ,看懂了。。。。捞了呀自个 嘿嘿
标签:range max else span long style 初始化 for 遍历
原文地址:https://www.cnblogs.com/letianpaiai/p/13874260.html