首页 > 其他 > 详细

leetcode1299

时间:2019-12-29 14:09:30      阅读:71      评论:0      收藏:0      [点我收藏+]
 1 class Solution:
 2     def replaceElements(self, arr: List[int]) -> List[int]:
 3         n = len(arr)
 4         maxright = arr[-1]
 5         res = [-1]
 6         for i in range(n-2,-1,-1):
 7             right = arr[i+1]
 8             maxright = max(right,maxright)
 9             res.insert(0,maxright)
10         return res

从右向左遍历,每次更新右区间的最大值maxright,并将这个值插入结果数组的0下标位置。

leetcode1299

原文:https://www.cnblogs.com/asenyang/p/12114877.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!