<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Generation Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/category/generation/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/category/generation/</link>
	<description></description>
	<lastBuildDate>Sun, 29 Dec 2019 18:53:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>Generation Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/category/generation/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1304. Find N Unique Integers Sum up to Zero</title>
		<link>https://zxi.mytechroad.com/blog/generation/leetcode-1304-find-n-unique-integers-sum-up-to-zero/</link>
					<comments>https://zxi.mytechroad.com/blog/generation/leetcode-1304-find-n-unique-integers-sum-up-to-zero/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 29 Dec 2019 18:52:37 +0000</pubDate>
				<category><![CDATA[Generation]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[generation]]></category>
		<category><![CDATA[O(n)]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=6018</guid>

					<description><![CDATA[<p>Given an integer&#160;n, return&#160;any&#160;array containing&#160;n&#160;unique&#160;integers such that they add up to 0. Example 1: Input: n = 5 Output: [-7,-1,1,3,4] Explanation: These arrays also are&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/generation/leetcode-1304-find-n-unique-integers-sum-up-to-zero/">花花酱 LeetCode 1304. Find N Unique Integers Sum up to Zero</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Given an integer&nbsp;<code>n</code>, return&nbsp;<strong>any</strong>&nbsp;array containing&nbsp;<code>n</code>&nbsp;<strong>unique</strong>&nbsp;integers such that they add up to 0.</p>



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> n = 5
<strong>Output:</strong> [-7,-1,1,3,4]
<strong>Explanation:</strong> These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4].
</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> n = 3
<strong>Output:</strong> [-1,0,1]
</pre>



<p><strong>Example 3:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> n = 1
<strong>Output:</strong> [0]
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>1 &lt;= n &lt;= 1000</code></li></ul>



<h2><strong>Solution: Generation</strong></h2>



<p>Use numbers from {-n/2, &#8230; n/2} + {0 if n is odd}</p>



<p>Time complexity: O(n)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  vector&lt;int&gt; sumZero(int n) {
    vector&lt;int&gt; ans;
    for (int i = 1; i &lt;= n / 2; ++i) {
      ans.push_back(i);
      ans.push_back(-i);
    }
    if (ans.size() != n) ans.push_back(0);
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/generation/leetcode-1304-find-n-unique-integers-sum-up-to-zero/">花花酱 LeetCode 1304. Find N Unique Integers Sum up to Zero</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/generation/leetcode-1304-find-n-unique-integers-sum-up-to-zero/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
