这个题目就是用stack, 分别将nums2里面每个对应的next bigger number找到, 如果没有, 那么为-1, 并且存到d里面. T :O(m) m = len(nums) Code classSolution(object):defnextGreaterElement(self, findNums, nums): stack,d, ans=[],{}, []fornuminnums:whilestackandnum > stack[-1]: d[stack.p...
When hitting a greater element x, pop up all the smaller element in the stack and mark their next greater element as x and store in the map. Time Complexity: O(n). n = nums1.length. Space: O(n). AC Java: 1classSolution {2publicint[] nextGreaterElement(int[] nums1,int[] nums2...
this stack we are gonna to use is actually a mono decrease stack, and we store the element of nums1 as the key, and the final results as the value corresponding to that element in nums1. public int[] nextGreaterElement(int[] findNums, int[] nums) { Map<Integer, Integer> map = ne...