Python beats 100%
Use the stack to record the reversed array nums. Loop the array from last integer to the first one. If the last integer in stack is bigger than the current inte
Use the stack to record the reversed array **nums**. Loop the array from last integer to the first one. If the last integer in stack is bigger than the current interger in array, we have found the answer. Otherwise, we need to keep pop up the integer in stack. Besides, we need to push the current integer to the stack in each step.\n```\nclass Solution(object):\n    def nextGreaterElements(self, nums):\n        n = len(nums)\n        ret = [-1] * n\n        stack = nums[::-1]\n        for i in range(n - 1, -1, -1):\n            while stack and stack[-1] <= nums[i]:\n                stack.pop()\n            if stack:\n                ret[i] = stack[-1]\n            stack.append(nums[i])\n        return ret\n```
[]