<?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>arrays Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/arrays/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/arrays/</link>
	<description></description>
	<lastBuildDate>Tue, 29 Mar 2022 02:45:38 +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>arrays Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/arrays/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 2215. Find the Difference of Two Arrays</title>
		<link>https://zxi.mytechroad.com/blog/hashtable/leetcode-2215-find-the-difference-of-two-arrays/</link>
					<comments>https://zxi.mytechroad.com/blog/hashtable/leetcode-2215-find-the-difference-of-two-arrays/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Tue, 29 Mar 2022 02:44:45 +0000</pubDate>
				<category><![CDATA[Hashtable]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[distinct]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[hashtable]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=9584</guid>

					<description><![CDATA[<p>Given two&#160;0-indexed&#160;integer arrays&#160;nums1&#160;and&#160;nums2, return&#160;a list&#160;answer&#160;of size&#160;2&#160;where: answer[0]&#160;is a list of all&#160;distinct&#160;integers in&#160;nums1&#160;which are&#160;not&#160;present in&#160;nums2. answer[1]&#160;is a list of all&#160;distinct&#160;integers in&#160;nums2&#160;which are&#160;not&#160;present in&#160;nums1. Note&#160;that the integers&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/hashtable/leetcode-2215-find-the-difference-of-two-arrays/">花花酱 LeetCode 2215. Find the Difference of Two Arrays</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 two&nbsp;<strong>0-indexed</strong>&nbsp;integer arrays&nbsp;<code>nums1</code>&nbsp;and&nbsp;<code>nums2</code>, return&nbsp;<em>a list</em>&nbsp;<code>answer</code>&nbsp;<em>of size</em>&nbsp;<code>2</code>&nbsp;<em>where:</em></p>



<ul><li><code>answer[0]</code>&nbsp;<em>is a list of all&nbsp;<strong>distinct</strong>&nbsp;integers in</em>&nbsp;<code>nums1</code>&nbsp;<em>which are&nbsp;<strong>not</strong>&nbsp;present in</em>&nbsp;<code>nums2</code><em>.</em></li><li><code>answer[1]</code>&nbsp;<em>is a list of all&nbsp;<strong>distinct</strong>&nbsp;integers in</em>&nbsp;<code>nums2</code>&nbsp;<em>which are&nbsp;<strong>not</strong>&nbsp;present in</em>&nbsp;<code>nums1</code>.</li></ul>



<p><strong>Note</strong>&nbsp;that the integers in the lists may be returned in&nbsp;<strong>any</strong>&nbsp;order.</p>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> nums1 = [1,2,3], nums2 = [2,4,6]
<strong>Output:</strong> [[1,3],[4,6]]
<strong>Explanation:
</strong>For nums1, nums1[1] = 2 is present at index 0 of nums2, whereas nums1[0] = 1 and nums1[2] = 3 are not present in nums2. Therefore, answer[0] = [1,3].
For nums2, nums2[0] = 2 is present at index 1 of nums1, whereas nums2[1] = 4 and nums2[2] = 6 are not present in nums2. Therefore, answer[1] = [4,6].</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> nums1 = [1,2,3,3], nums2 = [1,1,2,2]
<strong>Output:</strong> [[3],[]]
<strong>Explanation:
</strong>For nums1, nums1[2] and nums1[3] are not present in nums2. Since nums1[2] == nums1[3], their value is only included once and answer[0] = [3].
Every integer in nums2 is present in nums1. Therefore, answer[1] = [].
</pre>



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



<ul><li><code>1 &lt;= nums1.length, nums2.length &lt;= 1000</code></li><li><code>-1000 &lt;= nums1[i], nums2[i] &lt;= 1000</code></li></ul>



<h2><strong>Solution: Hashtable</strong></h2>



<p>Use two hashtables to store the unique numbers of array1 and array2 respectfully.</p>



<p>Time complexity: O(m+n)<br>Space complexity: O(m+n)</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;vector&lt;int&gt;&gt; findDifference(vector&lt;int&gt;&amp; nums1, vector&lt;int&gt;&amp; nums2) {
    vector&lt;vector&lt;int&gt;&gt; ans(2);
    unordered_set&lt;int&gt; s1(begin(nums1), end(nums1));
    unordered_set&lt;int&gt; s2(begin(nums2), end(nums2));
    for (int x : s1)
      if (!s2.count(x)) ans[0].push_back(x);
    for (int x : s2)
      if (!s1.count(x)) ans[1].push_back(x);
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/hashtable/leetcode-2215-find-the-difference-of-two-arrays/">花花酱 LeetCode 2215. Find the Difference of Two Arrays</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/hashtable/leetcode-2215-find-the-difference-of-two-arrays/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
