Skip to content

Commit 8f1679a

Browse files
committed
committed from zkp
1 parent 57168b7 commit 8f1679a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

LeetCode/nextGreaterElement-1.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from collections import deque
2+
class Solution(object):
3+
def nextGreaterElement(self, nums1, nums2):
4+
"""
5+
:type nums1: List[int]
6+
:type nums2: List[int]
7+
:rtype: List[int]
8+
"""
9+
s = deque()
10+
d = {}
11+
for i in nums2:
12+
while s and s[-1] < i:
13+
d[s.pop()] = i
14+
s.append(i)
15+
return [d[i] if i in d else -1 for i in nums1]

0 commit comments

Comments
 (0)