Skip to content

Instantly share code, notes, and snippets.

@luoheng23
Created December 30, 2019 01:33
Show Gist options
  • Save luoheng23/31edfc86b82653e88ec2f9e3120d2501 to your computer and use it in GitHub Desktop.
Save luoheng23/31edfc86b82653e88ec2f9e3120d2501 to your computer and use it in GitHub Desktop.
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