serega1112

496

Dec 24th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. class Solution:
  2.     def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]:
  3.        
  4.         st = []
  5.         next_gt = dict()
  6.        
  7.         for num in nums2:
  8.             while st and num > st[-1]:
  9.                 x = st.pop()
  10.                 next_gt[x] = num
  11.             st.append(num)
  12.            
  13.         return [next_gt.get(elem, -1) for elem in nums1]
Advertisement
Add Comment
Please, Sign In to add comment