• Skip to primary navigation
  • Skip to content
  • Skip to footer
zhicheng xie's demo blog
  • Quick-Start Guide

    Your Name

    I am an amazing person.

    • Somewhere

    Find N Unique Integers Sum up to Zero

    less than 1 minute read

    <-E> Find N Unique Integers Sum up to Zero

    class Solution {
    public:
        vector<int> sumZero(int n) {
            vector<int> ans;
            if(n % 2) {
                ans.push_back(0);
                
            }
            else ;
            for(int i = 1; i <= n / 2; i++) {
                ans.push_back(i);
                ans.push_back(-i);
            }
            return ans;
        }
    };
    

    Tags: Algorithms, C++, Leetcode

    Updated: January 16, 2020

    Share on

    Twitter Facebook LinkedIn
    Previous Next

    You may also enjoy

    Decode Ways

    less than 1 minute read

    <-M 91> Decode Ways

    Word Break

    less than 1 minute read

    <-H 139> Word Break

    Distinct Subsequences

    less than 1 minute read

    <-H 115> Distinct Subsequences

    Edit Distance

    less than 1 minute read

    <-H 72> Edit Distance

    • Follow:
    • Feed
    © 2023 zhicheng xie's blog. Powered by Jekyll & Minimal Mistakes.