pure-jcore/src/main/java/leetcode/FourSum.java
/**
     * all combinations with two indexes in 2d array
     */
all combinations with two indexes in 2d array
all combinations with two indexes in 2d array
public int[][] twoSumsAll(int[] nums, int target) {
        List<int[]> resultList = new ArrayList<>();
        int len = nums.length;
        HashMap<Integer, Integer> hashMap = new HashMap<>();
        for (int i = 0; i < len; i++) {
            int current = nums[i];
            int compliment = target - current;
            if (hashMap.containsKey(compliment)) {
                resultList.add(new int[] { hashMap.get(compliment), i });
            } else {
                hashMap.put(current, i);
            }
        }
        return convertListTo2dArrayWithEachOf2Elements(resultList);
    }
public int [ ] [ ] twoSumsAll ( int [ ] nums , int target ) { List < int [ ] > resultList = new ArrayList < > ( ) ; int len = nums . length ; HashMap < Integer , Integer > hashMap = new HashMap < > ( ) ; for ( int i = 0 ; i < len ; i ++ ) { int current = nums [ i ] ; int compliment = target - current ; if ( hashMap . containsKey ( compliment ) ) { resultList . add ( new int [ ] { hashMap . get ( compliment ) , i } ) ; } else { hashMap . put ( current , i ) ; } } return convertListTo2dArrayWithEachOf2Elements ( resultList ) ; }
all combinations with two indexes in 2d array
all combinations with two indexes in 2d array
// store 1d arrays // convert list of int[] to 2d array