Somebody help me improve my code, I think java can do better than 223ms +


  • 14
    B
     public int[] twoSum(int[] numbers, int target) {
        HashMap<Integer , Integer> map = new HashMap<>();
        for(int i=0;i<numbers.length;i++){
            if(! map.containsKey(numbers[i]))
                map.put(target-numbers[i],i+1);
            else
                return new int[]{ map.get(numbers[i]) , i+1};
        }
        return new int[]{-1,-1};
    }

Log in to reply
 

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