码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode "496. Next Greater Element I" !

时间:2017-02-13 12:18:26      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:each   leetcode   ...   end   span   style   elf   self   log   

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" !

标签:each   leetcode   ...   end   span   style   elf   self   log   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!