首页 > 其他 > 详细

LeetCode "496. Next Greater Element I" !

时间:2017-02-13 12:15:43      阅读:184      评论:0      收藏:0      [点我收藏+]

Play it in your mind.. or it may be hard to reach to this intuitive solution...

class Solution(object):
    def nextGreaterElement(self, findNums, nums):
        hm = {}
        stk = []
        for n in nums:
            while len(stk)>0 and stk[-1] < n:
                hm[stk[-1]] = n
                stk.pop()
            stk.append(n)
        
        return list(map(lambda x: hm[x] if x in hm else -1, findNums))

LeetCode "496. Next Greater Element I" !

原文:http://www.cnblogs.com/tonix/p/6393091.html

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