class Solution:
def sumZero(self, n: int) -> List[int]:
prefix_sum = 0
res = []
# 1, n-1
for i in range(1, n):
res.append(i)
prefix_sum = prefix_sum + i
# sum(from 1 to n-1)
res.append(-prefix_sum)
return res
# def sumZero(self, n: int) -> List[int]:
# # 1,n-1
# prefix = list(range(1, n))
# # sum(from 1 to n-1)
# return prefix + [-sum(prefix)]
Download Find N Unique Integers Sum up to Zero.pyLeetcode 1304 Find N Unique Integers Sum up to Zero problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.