Help! My Go solution time exceeded


  • 0
    K

    i think my algorithm should not too worse to ac.....maybe?

    func productExceptSelf(nums []int) []int {
    	var length = len(nums)
    	var ret []int = make([]int, length)
    	var multiple int = 1
    	var idx int = 0
    	for idx < length-1 {
    		multiple *= nums[idx]
    		ret[idx+1] = multiple
    		idx++
    	}
    	idx = length - 1
    	multiple = 1
    	for idx > 0 {
    	    if ret[idx-1] == 0 {
    	        ret[idx-1] = 1
    	    }
    		multiple *= nums[idx]
    		ret[idx-1] *= multiple
    		idx--
    	}
    	return ret
    }
    

Log in to reply
 

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