503 Next Greater Element II
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 circularly to find its next greater number. If it doesn't exist, output -1 for this number.
Example 1:
Note:The length of given array won't exceed 10000.
The Idea: I hashed the locations for the second list, and use that as the starting point of traversing the first list until a greater element is reached.
Last updated