My Javascript code


  • 0
    L

    /**

    • @param {number[]} findNums
    • @param {number[]} nums
    • @return {number[]}
      */
      var nextGreaterElement = function(findNums, nums) {
      var res=[];
      var len2=nums.length;
      var len1=findNums.length;
      for(var i=0;i<len1;i++){
      var index=nums.indexOf(findNums[i]);
      if(index==len2-1){
      res.push(-1);
      }
      else{
      for(var j=index+1;j<len2;j++){
      if(nums[j]>findNums[i]){
      res.push(nums[j]);
      break;
      }
      if(j==len2-1){
      res.push(-1);
      }
      }
      }
      }
      return res;
      };

Log in to reply
 

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