Java use ArrayList

  • 0

    Here is my code,just use ArrayList to get the index.

    public class Solution {
        public int[] nextGreaterElement(int[] findNums, int[] nums) {
        int[] ret=new int[findNums.length];
        ArrayList<Integer> al=new ArrayList<Integer>();
        for(int n:nums) al.add(n);
        for(int i=0;i<findNums.length;i++){
            int currInd=al.indexOf(findNums[i])+1;
            for(int j=currInd;j<=nums.length;j++){
            else if(nums[j]>findNums[i]){ret[i]=nums[j];break;}
        return ret;

Log in to reply

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