{"id":461,"date":"2020-09-26T10:44:18","date_gmt":"2020-09-26T02:44:18","guid":{"rendered":"http:\/\/39.96.58.60\/?p=461"},"modified":"2022-10-18T16:39:14","modified_gmt":"2022-10-18T08:39:14","slug":"leetcode-349-%e4%b8%a4%e4%b8%aa%e6%95%b0%e7%bb%84%e7%9a%84%e4%ba%a4%e9%9b%86","status":"publish","type":"post","link":"http:\/\/www.yatenglg.cn\/blog\/?p=461","title":{"rendered":"Leetcode 349. \u4e24\u4e2a\u6570\u7ec4\u7684\u4ea4\u96c6"},"content":{"rendered":"<p>\u7ed9\u5b9a\u4e24\u4e2a\u6570\u7ec4\uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u5b83\u4eec\u7684\u4ea4\u96c6\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>nums1 = [1,2,2,1], nums2 = [2,2]\n\n<strong>\u8f93\u51fa\uff1a<\/strong>[2]\n\n<\/pre>\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>nums1 = [4,9,5], nums2 = [9,4,9,8,4]\n\n<strong>\u8f93\u51fa\uff1a<\/strong>[9,4]<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li>\u8f93\u51fa\u7ed3\u679c\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4e00\u5b9a\u662f\u552f\u4e00\u7684\u3002<\/li>\n<li>\u6211\u4eec\u53ef\u4ee5\u4e0d\u8003\u8651\u8f93\u51fa\u7ed3\u679c\u7684\u987a\u5e8f\u3002<\/li>\n<\/ul>\n<p>**\u96be\u5ea6**: Easy<\/p>\n<p>**\u6807\u7b7e**: \u6392\u5e8f\u3001 \u54c8\u5e0c\u8868\u3001 \u53cc\u6307\u9488\u3001 \u4e8c\u5206\u67e5\u627e\u3001<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-python\" data-lang=\"Python\"><code>\n# -*- coding: utf-8 -*-\n# @Author  : LG\n\n\"\"\"\n\u6267\u884c\u7528\u65f6\uff1a56 ms, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8685.56% \u7684\u7528\u6237\n\u5185\u5b58\u6d88\u8017\uff1a13.8 MB, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e865.23% \u7684\u7528\u6237\n\n\u89e3\u9898\u601d\u8def\uff1a\n    \u96c6\u5408 \u53bb\u91cd\n\"\"\"\nclass Solution:\n    def intersection(self, nums1: List[int], nums2: List[int]) -&gt; List[int]:\n        nums1 = set(nums1)\n        nums2 = set(nums2)\n        if len(nums1) &gt; len(nums2):\n            nums2, nums1 = nums1, nums2\n        return [i for i in nums1 if i in nums2]<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e24\u4e2a\u6570\u7ec4\uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u5b83\u4eec\u7684\u4ea4\u96c6\u3002 &nbsp; \u793a\u4f8b 1\uff1a \u8f93\u5165\uff1anums1 = [1,2,2,1&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/461"}],"collection":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=461"}],"version-history":[{"count":1,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/461\/revisions"}],"predecessor-version":[{"id":462,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/461\/revisions\/462"}],"wp:attachment":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=461"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}