1304. Find N Unique Integers Sum up to Zero

Given an integer n, return any array containing n unique integers such that they add up to 0.

分奇偶吧,偶就给i和-i,奇的话就最后多给个0

class Solution(object):
    def sumZero(self, n):
        """
        :type n: int
        :rtype: List[int]
        """
        ans = []
        for i in range(1, n // 2 + 1, 1):
            ans.append(i)
            ans.append(-i)
        if n % 2 == 1:
            ans.append(0)
        return ans
原文地址:https://www.cnblogs.com/whatyouthink/p/13207398.html