Next Greater Element I LeetCode solution in Python

1
class Solution:
2
def nextGreaterElement(self, nums1, nums2):
3
dic, stack = {}, []
4

5
for num in nums2[::-1]:
6
while stack and num > stack[-1]:
7
stack.pop()
8
if stack:
9
dic[num] = stack[-1]
10
stack.append(num)
11

12
return [dic.get(num, -1) for num in nums1]

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0