javascript solution


  • 0
    E

    This is my javascript solution:

    /**
     * @param {number[]} A
     * @param {number[]} B
     * @param {number[]} C
     * @param {number[]} D
     * @return {number}
     */
    var fourSumCount = function(A, B, C, D) {
        let map = new Map();
        let res = 0;
    
        for (let i = 0; i < C.length; i++) {
        	for (let j = 0; j < D.length; j++) {
        		map.set(C[i] + D[j], (typeof map.get(C[i] + D[j]) == 'undefined') ? 1 : map.get(C[i] + D[j]) + 1);
        	}
        }
    
        for (let i = 0; i < A.length; i++) {
        	for (let j = 0; j < B.length; j++) {
        		res += (typeof map.get((A[i] + B[j]) * -1) == 'undefined') ? 0 : map.get((A[i] + B[j]) * -1);
        	}
        }
    
        return res;
    };
    

Log in to reply
 

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