simple solution java


  • 0
    E

    public class Solution {
    public int[] nextGreaterElement(int[] findNums, int[] nums) {
    int[] res=new int[findNums.length];
    for(int i=0;i<findNums.length;i++){
    int ok=-1;
    int ind=0;
    for(int j=0;j<nums.length;j++){
    if(findNums[i]==nums[j])
    ind=j;
    }
    for (int k=ind;k<nums.length;k++)
    {
    if(nums[k]>findNums[i]){
    ok=nums[k];
    break;
    }

            }
            res[i]=ok;
        }
        return res;
    }
    

    }


Log in to reply
 

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