LeetCode 1304 Find N Unique Integers Sum up to Zero

LeetCode 1304 Find N Unique Integers Sum up to Zero Problem

Download Code
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.py

List of all Find N Unique Integers Sum up to Zero problems

Leetcode 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.