Why is indexOf wrong here and is my logic also wrong?


  • 0
    S

    public class Solution {
    public int[] nextGreaterElement(int[] findNums, int[] nums) {
    List<Integer> result= new ArrayList<Integer>();
    for (int i=0; i<findNums.length; i++)
    {
    int index= nums.indexOf(findNums[i]);
    //System.out.println(index);
    for(int j=index; j<nums.length; j++)
    {
    if(nums[j]>findNums[i])
    {result.add(nums[j]);break;}
    else
    result.add(-1);
    }
    }
    }

    }


Log in to reply
 

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