Golang O(n) solution, simple


  • 0
    func integerBreak(n int) int {
    
    	if n == 2 {
    		return 1
    	}
    	if n == 3 {
    		return 2
    	}
    	max := 1
    	for {
    		if n > 4 {
    			max *= 3
    			n -= 3
    		} else {
    			break
    		}
    	}
    	max *= n
    
    	return max
    }
    

Log in to reply
 

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