js beat 96.86%


  • 1
    Y
    var nextGreaterElement = function(findNums, nums) {
        var map = {};
        nums.forEach((num, i)=>{
            map[num] = i;
        });
        return findNums.map(num=>{
            for (var i = map[num]; i < nums.length; i++) {
                if (nums[i] > num) return nums[i];
            }
            return -1;
        })
    };
    

Log in to reply
 

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