Leetcode Note: Go - Find N Unique Integers Sum Up to Zero

Find N Unique Integers Sum up to Zero - LeetCode
https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/

  • Go 言語で取り組んだメモ

回答

Go short simple solution, 0ms - Find N Unique Integers Sum up to Zero - LeetCode
https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/solutions/1051397/go-short-simple-solution-0ms/

func sumZero(n int) []int {
    a := make([]int, n)
    for i := n % 2; i < n; i += 2 {
        a[i], a[i + 1] = i + 1, -(i + 1)
    }
    return a
}