pure-jcore/src/main/java/leetcode/FourSum.java
/**
     * all combinations in list of three indexes in 1d array
     */
all combinations in list of three indexes in 1d array
all combinations in list of three indexes in 1d array
public List<int[]> threeSums_WithGivenIndex(int[] nums, int target, int givenIndex) {
        int len = nums.length;
        if (givenIndex >= len) {
            throw new IllegalArgumentException(String.format("Wrong FROMINDEX[%d]", givenIndex));
        }
        List<int[]> resultList = new ArrayList<>();
        HashMap<Integer, Integer> hashMap = new HashMap<>();
        int fromIndex = givenIndex + 1;
        for (int i = fromIndex; i < len; i++) {
            int current = nums[i];
            int compliment = target - current;
            if (hashMap.containsKey(compliment)) {
                resultList.add(new int[] { givenIndex, hashMap.get(compliment), i });
            } else {
                hashMap.put(current, i);
            }
        }
        return resultList;
    }
public List < int [ ] > threeSums_WithGivenIndex ( int [ ] nums , int target , int givenIndex ) { int len = nums . length ; if ( givenIndex >= len ) { throw new IllegalArgumentException ( String . format ( "Wrong FROMINDEX[%d]" , givenIndex ) ) ; } List < int [ ] > resultList = new ArrayList < > ( ) ; HashMap < Integer , Integer > hashMap = new HashMap < > ( ) ; int fromIndex = givenIndex + 1 ; for ( int i = fromIndex ; i < len ; i ++ ) { int current = nums [ i ] ; int compliment = target - current ; if ( hashMap . containsKey ( compliment ) ) { resultList . add ( new int [ ] { givenIndex , hashMap . get ( compliment ) , i } ) ; } else { hashMap . put ( current , i ) ; } } return resultList ; }
all combinations in list of three indexes in 1d array
all combinations in list of three indexes in 1d array
// store 1d arrays