javascript 10 lines, beats 97%


  • 0
    W
    var nextGreaterElement = function(findNums, nums) {
        let obj = {}
        let stack = []
        for (let i of nums) {
            while (stack[stack.length - 1] < i) {
                obj[stack.pop()] = i
            }
            stack.push(i)
        }
        return findNums.map(i => obj[i] || -1)
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.