Memory Limit Exceeded


  • 0
    W

    Hi all
    Could anyone help me to decrease the memory my code use?

    func fourSumCount(A []int, B []int, C []int, D []int) int {
    	var m map[int]int = make(map[int]int)
    	var result int
    	result = 0
    	for i := 0; i < len(A); i++ {
    		for j:= 0; j < len(B); j++ {
    			if val, ok := m[A[i]+B[j]]; ok {
    				m[A[i]+B[j]] = val + 1
    			}else {
    				m[A[i]+B[j]] = 1
    			}
    		}
    	}
    	for i := 0; i < len(C) ; i++ {
    		for j := 0; j < len(D); j++ {
    			if val, ok := m[-C[i]-D[j]]; ok {
    				result += val
    			}
    
    		}
    	}
    
    	return result
    }
    

Log in to reply
 

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