# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # pick candy # @param arr int整型一维数组 the array # @return int整型 # class Solution: def candy(self , arr: List[int]) -> int: # write code here if len(arr)==0: return 0 elif len(arr)==1: return 1 nums=[1] * len(arr) for i in range(1, len(arr)): if arr[i]>arr[i-1]: nums[i]= nums[i-1]+1 res = nums[len(arr)-1] for j in range(len(arr)-2, -1,-1): if arr[j]>arr[j+1] and nums[j]<=nums[j+1]: nums[j]=nums[j+1]+1 res += nums[j] return res