Accepted ArrayList Solution


  • 0
    D
    int ret[] = new int[2];
            List<Integer> list = new ArrayList<Integer>();
            int index = 0;
            for(int i=0;i<nums.length;i++) {
                if(list.isEmpty()) {
                    list.add(nums[i]);
                } else {
                    if(list.contains(target-nums[i])) {
                        ret[0] = list.indexOf(target-nums[i]);
                        ret[1] = i;
                        return ret;
                    } else {
                        list.add(nums[i]);
                    }
                }
                index++;
            }
            return ret;
    

Log in to reply
 

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