Created
December 30, 2019 01:33
-
-
Save luoheng23/31edfc86b82653e88ec2f9e3120d2501 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func sumZero(n int) []int { | |
if n <= 0 { | |
return []int{} | |
} | |
res := make([]int, n) | |
for i := 0; i < n - 1; i++ { | |
res[i] = i | |
} | |
res[n-1] = - ((n - 2) * (n - 1) >> 1) | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment