Skip to content

Commit ffe67a8

Browse files
author
Daniel Nallapalli
committed
Solution #496 (Python) - Daniel - 16/06/2025 - commit Dijkstra-Edu#1
1 parent 76b0b15 commit ffe67a8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)