We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 76b0b15 commit ffe67a8Copy full SHA for ffe67a8
Arrays101/#496 - Next Greater Element - Easy/Solution.py
@@ -0,0 +1,20 @@
1
+class Solution(object):
2
+ def nextGreaterElement(self, nums1, nums2):
3
+ """
4
+ :type nums1: List[int]
5
+ :type nums2: List[int]
6
+ :rtype: List[int]
7
8
+ next_greater = {}
9
+ stack = []
10
+
11
+ for num in nums2:
12
+ while stack and num > stack[-1]:
13
+ prev = stack.pop()
14
+ next_greater[prev] = num
15
+ stack.append(num)
16
17
+ for num in stack:
18
+ next_greater[num] = -1
19
20
+ return [next_greater[num] for num in nums1]
0 commit comments