这个题目就是用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...
Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the first greater number to its traversing-order next in the array, which means you could search ci...
Java for LeetCode 122 Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a given stock on day i. Design an al ... okhttp 请求list数据实例 public class DataBean { /** * id : 61684 * movieName : <猜火车2>先导预告片 * cover...