[LeetCode]#1304. Find N Unique Integers Sum up to Zero

Input: n = 5
Output: [-7,-1,1,3,4]
Explanation: These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4].
Input: n = 3
Output: [-1,0,1]
Input: n = 1
Output: [0]
class Solution:
def sumZero(self, n):
ans=[]
for i in range(1,n//2+1):
ans.append(i)
ans.append(-i)
if n % 2 !=0:
ans.append(0)
return ans

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store