{"id":9685,"date":"2022-04-27T08:47:02","date_gmt":"2022-04-27T15:47:02","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=9685"},"modified":"2022-04-27T08:47:19","modified_gmt":"2022-04-27T15:47:19","slug":"leetcode-2248-intersection-of-multiple-arrays","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/hashtable\/leetcode-2248-intersection-of-multiple-arrays\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 2248. Intersection of Multiple Arrays"},"content":{"rendered":"\n<p>Given a 2D integer array&nbsp;<code>nums<\/code>&nbsp;where&nbsp;<code>nums[i]<\/code>&nbsp;is a non-empty array of&nbsp;<strong>distinct<\/strong>&nbsp;positive integers, return&nbsp;<em>the list of integers that are present in&nbsp;<strong>each array<\/strong>&nbsp;of<\/em><code>nums<\/code><em>&nbsp;sorted in&nbsp;<strong>ascending order<\/strong><\/em>.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> nums = [[<strong>3<\/strong>,1,2,<strong>4<\/strong>,5],[1,2,<strong>3<\/strong>,<strong>4<\/strong>],[<strong>3<\/strong>,<strong>4<\/strong>,5,6]]\n<strong>Output:<\/strong> [3,4]\n<strong>Explanation:<\/strong> \nThe only integers present in each of nums[0] = [<strong>3<\/strong>,1,2,<strong>4<\/strong>,5], nums[1] = [1,2,<strong>3<\/strong>,<strong>4<\/strong>], and nums[2] = [<strong>3<\/strong>,<strong>4<\/strong>,5,6] are 3 and 4, so we return [3,4].<\/pre>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> nums = [[1,2,3],[4,5,6]]\n<strong>Output:<\/strong> []\n<strong>Explanation:<\/strong> \nThere does not exist any integer present both in nums[0] and nums[1], so we return an empty list [].\n<\/pre>\n\n\n\n<p><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>1 &lt;= nums.length &lt;= 1000<\/code><\/li><li><code>1 &lt;= sum(nums[i].length) &lt;= 1000<\/code><\/li><li><code>1 &lt;= nums[i][j] &lt;= 1000<\/code><\/li><li>All the values of&nbsp;<code>nums[i]<\/code>&nbsp;are&nbsp;<strong>unique<\/strong>.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution: Hashtable<\/strong><\/h2>\n\n\n\n<p>Time complexity: O(n)<br>Space complexity: O(n)<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"c++\">\n\/\/ Author: Huahua\nclass Solution {\npublic:\n  vector<int> intersection(vector<vector<int>>& nums) {\n    vector<int> m(1001);\n    for (const auto& arr : nums)\n      for (const int x : arr)\n        ++m[x];\n    vector<int> ans;\n    for (int i = 0; i < m.size(); ++i)\n      if (m[i] == nums.size())\n        ans.push_back(i);\n    return ans;\n  }\n};\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Given a 2D integer array&nbsp;nums&nbsp;where&nbsp;nums[i]&nbsp;is a non-empty array of&nbsp;distinct&nbsp;positive integers, return&nbsp;the list of integers that are present in&nbsp;each array&nbsp;ofnums&nbsp;sorted in&nbsp;ascending order. Example 1: Input: nums&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[20,222,82],"class_list":["post-9685","post","type-post","status-publish","format-standard","hentry","category-hashtable","tag-array","tag-easy","tag-hashtable","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/9685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=9685"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/9685\/revisions"}],"predecessor-version":[{"id":9687,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/9685\/revisions\/9687"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=9685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=9685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=9685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}