{"id":1475,"date":"2021-12-15T01:17:10","date_gmt":"2021-12-14T17:17:10","guid":{"rendered":"https:\/\/www.xinot.icu\/?p=1475"},"modified":"2021-12-15T01:23:15","modified_gmt":"2021-12-14T17:23:15","slug":"%e4%bd%8d%e8%bf%90%e7%ae%97%e8%a7%84%e5%be%8b%e4%b8%8e%e7%9b%b8%e5%85%b3%e9%a2%98%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.xinot.icu\/?p=1475","title":{"rendered":"\u4f4d\u8fd0\u7b97\u89c4\u5f8b\u4e0e\u76f8\u5173\u9898\u89e3"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"1475\" class=\"elementor elementor-1475\" data-elementor-settings=\"[]\">\n\t\t\t\t\t\t\t<div class=\"elementor-section-wrap\">\n\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-92fc8b3 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"92fc8b3\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-4736bf8\" data-id=\"4736bf8\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-34f2248 elementor-widget elementor-widget-heading\" data-id=\"34f2248\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">\u4f4d\u8fd0\u7b97\u89c4\u5f8b\u4e0e\u76f8\u5173\u9898\u89e3<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-5578c5b elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"5578c5b\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-be6afca\" data-id=\"be6afca\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-663b171 elementor-widget elementor-widget-global elementor-global-1379 elementor-widget-heading\" data-id=\"663b171\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">\u6b63\u6587<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5ef3168 elementor-widget-divider--view-line elementor-widget elementor-widget-global elementor-global-1396 elementor-widget-divider\" data-id=\"5ef3168\" data-element_type=\"widget\" data-settings=\"{&quot;_animation&quot;:&quot;none&quot;,&quot;_animation_delay&quot;:1000}\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d7503be elementor-widget elementor-widget-text-editor\" data-id=\"d7503be\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>\u3000\u3000\u4f4d\u8fd0\u7b97\u662f\u8ba1\u7b97\u673a\u4e2d\u6548\u7387\u6700\u9ad8\u7684\u4e00\u79cd\u8fd0\u7b97\u65b9\u5f0f\uff0c\u82e5\u80fd\u5c06\u539f\u6765\u7684\u8fd0\u7b97\u901a\u8fc7\u4f4d\u8fd0\u7b97\u5b9e\u73b0\uff0c\u5c06\u4f1a\u5927\u5927\u63d0\u9ad8\u6211\u4eec\u7684\u7b97\u6cd5\u6548\u7387\u3002\u5c31\u8fd0\u7b97\u901f\u5ea6\u6765\u8bb2\uff0c\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\uff1a<\/p><p>\u3000\u3000\u4f4d\u8fd0\u7b97 &gt; \u52a0\u51cf &gt; \u4e58\u9664 &gt; \u5e42\u8fd0\u7b97<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-6850bfc elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"6850bfc\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-41dbf7f\" data-id=\"41dbf7f\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-f532d1c elementor-widget elementor-widget-heading\" data-id=\"f532d1c\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">\u4f4d\u8fd0\u7b97\u89c4\u5f8b<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6198978 elementor-widget-divider--view-line elementor-widget elementor-widget-global elementor-global-1396 elementor-widget-divider\" data-id=\"6198978\" data-element_type=\"widget\" data-settings=\"{&quot;_animation&quot;:&quot;none&quot;,&quot;_animation_delay&quot;:1000}\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9cbe455 elementor-widget elementor-widget-text-editor\" data-id=\"9cbe455\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>\u3000\u3000\u4ea4\u6362\u5f8b\uff1a<\/p><p>\u3000\u3000\u3000\u3000a &amp; b = b &amp; a<\/p><p>\u3000\u3000\u3000\u3000a | b = b | a<\/p><p>\u3000\u3000\u3000\u3000a ^ b = b ^ a<\/p><p>\u3000\u3000\u7ed3\u5408\u5f8b\uff08\u4ec5\u9002\u7528\u4e8e\u5355\u4e2a\u4f4d\u8fd0\u7b97\u7b26\uff09\uff1a<\/p><p>\u3000\u3000\u3000\u3000(a | b) | c = a | (b | c)<\/p><p>\u3000\u3000\u3000\u3000(a &amp; b) &amp; c = a &amp; (b &amp; c)<\/p><p>\u3000\u3000\u3000\u3000(a ^ b) ^ c = a ^ (b ^ c)<\/p><p>\u3000\u3000\u5206\u914d\u5f8b\uff1a<\/p><p>\u3000\u3000\u3000\u3000(a &amp; b) | c = (a | c) &amp; (b | c)<\/p><p>\u3000\u3000\u3000\u3000(a | b) &amp; c = (a &amp; c) | (b &amp; c)<\/p><p>\u3000\u3000\u3000\u3000(a ^ b) &amp; c = (a &amp; c) ^ (b &amp; c)<\/p><p>\u3000\u3000\u3000\u3000\u5176\u4e2d\uff0c\u7b2c\u4e09\u6761\u89c4\u5f8b\u662f\u552f\u4e00\u4e00\u6761\uff0c\u6709\u300c\u5f02\u6216\u300d\u8fd0\u7b97\u60c5\u51b5\u4e0b\u6ee1\u8db3\u914d\u7387\u3002<\/p><p>\u3000\u3000\u4f4d\u8fd0\u7b97\u62b5\u6d88\uff1a<\/p><p>\u3000\u3000\u3000\u3000a &amp; (~a) = 0<\/p><p>\u3000\u3000\u3000\u3000a ^ a = 0<\/p><p>\u3000\u3000\u5224\u65ad\u5947\u5076\uff1a<\/p><p>\u3000\u3000\u3000\u3000a &amp; 1 == 0 ? \u5947 : \u5076<\/p><p>\u3000\u3000\u4fdd\u7559\u4e8c\u8fdb\u5236\u4e2d\u672b\u4f4d\u76841\uff1a<\/p><p>\u3000\u3000\u3000\u3000a &amp; -a<\/p><p>\u3000\u3000\u3000\u3000a &amp; (~a + 1)<\/p><p>\u3000\u3000\u3000\u3000\u6ce8\uff1a(~a + 1)\u662fa\u7684\u8865\u7801\u8868\u73b0\u5f62\u5f0f\uff0c\u5373-a<\/p><p>\u3000\u3000\u53bb\u9664\u4e8c\u8fdb\u5236\u4e2d\u7684\u672b\u4f4d1\uff1a<\/p><p>\u3000\u3000\u3000\u3000a &amp; (a \u2013 1)<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-058e04a elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"058e04a\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-1fd2690\" data-id=\"1fd2690\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-9f69626 elementor-widget elementor-widget-heading\" data-id=\"9f69626\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-aecc96e elementor-widget-divider--view-line elementor-widget elementor-widget-global elementor-global-1396 elementor-widget-divider\" data-id=\"aecc96e\" data-element_type=\"widget\" data-settings=\"{&quot;_animation&quot;:&quot;none&quot;,&quot;_animation_delay&quot;:1000}\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d6b7796 elementor-widget elementor-widget-text-editor\" data-id=\"d6b7796\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p><a href=\"https:\/\/leetcode-cn.com\/problems\/single-number\/\"><span style=\"text-decoration: underline;\"><strong>LeetCode No.136<\/strong><\/span><\/a><\/p><p>\u3000\u3000\u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u6574\u6570\u6570\u7ec4\uff0c\u9664\u4e86\u67d0\u4e2a\u5143\u7d20\u53ea\u51fa\u73b0\u4e00\u6b21\u4ee5\u5916\uff0c\u5176\u4f59\u6bcf\u4e2a\u5143\u7d20\u5747\u51fa\u73b0\u4e24\u6b21\u3002\u627e\u51fa\u90a3\u4e2a\u53ea\u51fa\u73b0\u4e86\u4e00\u6b21\u7684\u5143\u7d20\u3002<\/p><p>\u3000\u3000Eg.<\/p><p>\u3000\u3000\u3000\u3000\u8f93\u5165\uff1a[4, 1, 2, 1, 2]<\/p><p>\u3000\u3000\u3000\u3000\u8f93\u51fa\uff1a4<\/p><p>\u3000\u3000\u5c31\u666e\u904d\u7406\u6027\u800c\u8bba\uff0c\u8fd9\u9053\u9898\u6709\u8bb8\u591a\u7684\u89e3\u6cd5\uff0c\u4f46\u82e5\u60f3\u8981\u8fbe\u5230O(1)\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u548c\u7ebf\u6027\u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u4f7f\u7528\u4f4d\u8fd0\u7b97\u662f\u4e3a\u6570\u4e0d\u591a\u7684\u65b9\u6cd5\u3002\u5229\u7528\u4f4d\u8fd0\u7b97\u4e2d\u5f02\u6216\u8fd0\u7b97\u7684\u4ee5\u4e0b\u4e09\u4e2a\u6027\u8d28\uff1a<\/p><p>\u3000\u3000a ^ 0 = a<\/p><p>\u3000\u3000a ^ a = a<\/p><p>\u3000\u3000a ^ b = b ^ a<\/p><p>\u3000\u3000\u53ef\u4ee5\u5c06\u8f93\u5165\u6570\u7ec4\u4e2d\u6240\u6709\u51fa\u73b0\u5076\u6570\u6b21\u7684\u5143\u7d20\u76f8\u6d88\u4e3a0\uff0c\u7559\u4e0b\u552f\u4e00\u5947\u6570\u6b21\u7684\u76ee\u6807\u6570\u3002<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f6cc30a elementor-widget elementor-widget-code-highlight\" data-id=\"f6cc30a\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp>int singleNumber(int[] nums) {\r\n    int res = 0;\r\n    \r\n    for (int num : nums) {\r\n        res ^= num;\r\n    }\r\n    \r\n    return res;\r\n}<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-be4554d elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"be4554d\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-6304732\" data-id=\"6304732\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-06978ac elementor-widget elementor-widget-heading\" data-id=\"06978ac\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57 II<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-21d0f59 elementor-widget-divider--view-line elementor-widget elementor-widget-global elementor-global-1396 elementor-widget-divider\" data-id=\"21d0f59\" data-element_type=\"widget\" data-settings=\"{&quot;_animation&quot;:&quot;none&quot;,&quot;_animation_delay&quot;:1000}\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d49e078 elementor-widget elementor-widget-text-editor\" data-id=\"d49e078\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p><a href=\"https:\/\/leetcode-cn.com\/problems\/single-number-iii\/\"><span style=\"text-decoration: underline;\"><strong>LeetCode No.260<\/strong><\/span><\/a><\/p><p>\u3000\u3000\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u5176\u4e2d\u6070\u597d\u6709\u4e24\u4e2a\u5143\u7d20\u53ea\u51fa\u73b0\u4e00\u6b21\uff0c\u5176\u4f59\u6240\u6709\u5143\u7d20\u5747\u51fa\u73b0\u4e24\u6b21\u3002 \u627e\u51fa\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u90a3\u4e24\u4e2a\u5143\u7d20\u3002\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002<\/p><p>\u3000\u3000Eg.<\/p><p>\u3000\u3000\u3000\u3000\u8f93\u5165\uff1anums = [1, 2, 1, 3, 2, 5]<\/p><p>\u3000\u3000\u3000\u3000\u8f93\u51fa\uff1a[3, 5] \u6216 [5, 3]<\/p><p>\u3000\u3000\u5047\u8bbe\u6211\u4eec\u5bfb\u627e\u7684\u76ee\u6807\u6570\u662fa\u548cb\uff0c\u5229\u7528\u4e0a\u4e00\u9898\u7684\u7ecf\u9a8c\uff0c\u6211\u4eec\u5f88\u5feb\u53ef\u4ee5\u60f3\u51fa\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u6d88\u9664\u8f93\u5165\u6570\u7ec4\u4e2d\u6240\u6709\u51fa\u73b0\u4e24\u6b21\u7684\u5143\u7d20\u3002\u4f46\u7531\u4e8e\u76ee\u6807\u6570\u6709\u4e24\u4e2a\uff0c\u6240\u4ee5\u6700\u540e\u6211\u4eec\u83b7\u53d6\u7684\u7ed3\u679c\u503c\u662fa ^ b\uff0c\u6211\u4eec\u7528\u4e00\u4e2a\u53d8\u91cfxorsum\u5c06\u5176\u5b58\u50a8\u3002<\/p><p>\u3000\u3000\u6839\u636e\u9898\u610f\uff0c\u6211\u4eec\u77e5\u9053a\u4e0d\u7b49\u4e8eb\uff0c\u56e0\u6b64a ^ b\u7684\u503c\u4e0d\u4e3a0\uff0c\u65e2xorsum\u4e0d\u4f1a\u4e3a0\uff0c\u90a3\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7xorsum\u6765\u786e\u8ba4a\u4e0eb\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u4e0d\u540c\u7684\u67d0\u4e00\u4f4d\u3002\u5229\u7528\u4e0e\u8fd0\u7b97xorsum &amp; -xorsum\uff0c\u4fdd\u7559xorsum\u4e8c\u8fdb\u5236\u7684\u672b\u4f4d1\uff0c\u5047\u8bbe\u5176\u4e3a\u7b2cj\u4f4d\u3002<\/p><p>\u3000\u3000\u90a3\u4e48\u56de\u5230a\u548cb\uff0c\u56e0\u4e3aa ^ b\u7684\u4ea7\u7269xorsum\u7684\u7b2cj\u4f4d\u4e3a1\uff0c\u6240\u4ee5a\u548cb\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\uff0c\u7b2cj\u4f4d\u5fc5\u7136\u662f\u4e0d\u540c\u7684\u3002\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u8fd9\u4e00\u6761\u4ef6\uff0c\u5c06\u8f93\u5165\u6570\u7ec4\u4e2d\u7684\u6570\u533a\u5206\u4e3a\u4e24\u7c7b\uff0c\u5176\u4e2d\u4e00\u7c7b\uff0c\u6240\u6709\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u8fbe\u4e2d\u7b2cj\u4f4d\u662f1\uff1b\u53e6\u4e00\u7c7b\u5219\u662f0\u3002\u800ca\u548cb\u5206\u522b\u5728\u8fd9\u4e24\u7c7b\u6570\u4e4b\u4e2d\uff0c\u5e76\u4e14\u8f93\u5165\u6570\u7ec4\u4e2d\u51fa\u73b0\u4e24\u6b21\u7684\u6570\uff0c\u51fa\u73b0\u7684\u4e24\u6b21\u90fd\u4f1a\u88ab\u5305\u542b\u5728\u540c\u4e00\u7c7b\u4e2d\u3002\u6240\u4ee5\u6211\u4eec\u5c06\u8fd9\u4e24\u7c7b\u6570\u5168\u90e8\u5f02\u6216\u8d77\u6765\uff0c\u4fbf\u80fd\u5f97\u5230\u6211\u4eec\u9700\u8981\u7684\u4e24\u4e2a\u7ed3\u679c\u3002<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f57d436 elementor-widget elementor-widget-code-highlight\" data-id=\"f57d436\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp>int[] singleNumber(int[] nums) {\r\n    int res1 = 0, res2 = 0, xorsum = 0;\r\n\r\n    for (int num : nums) {\r\n        xorsum ^= num;\r\n    }\r\n\r\n    \/\/ \u4fdd\u7559ero\u4e8c\u8fdb\u5236\u4e2d\u7684\u6700\u540e\u4e00\u4f4d\r\n    xorsum &= -xorsum;\r\n\r\n    for (int num : nums) {\r\n        if ((xorsum & num) == 0) {\r\n            \/\/ \u4e00\u7c7b\r\n            res1 ^= num;\r\n        } else {    \/\/ (ero & num) != 0\r\n            \/\/ \u53e6\u5916\u4e00\u7c7b\r\n            res2 ^= num;\r\n        }\r\n    }\r\n\r\n    return new int[]{res1, res2};\r\n}<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-f19cd14 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"f19cd14\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-8fab145\" data-id=\"8fab145\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-0e0b87d elementor-widget elementor-widget-heading\" data-id=\"0e0b87d\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57 III<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9d1a9a8 elementor-widget-divider--view-line elementor-widget elementor-widget-global elementor-global-1396 elementor-widget-divider\" data-id=\"9d1a9a8\" data-element_type=\"widget\" data-settings=\"{&quot;_animation&quot;:&quot;none&quot;,&quot;_animation_delay&quot;:1000}\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e77a455 elementor-widget elementor-widget-text-editor\" data-id=\"e77a455\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p><a href=\"https:\/\/leetcode-cn.com\/problems\/single-number-ii\/\"><span style=\"text-decoration: underline;\"><strong>LeetCode No.137<\/strong><\/span><\/a><\/p><p>\u3000\u3000\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u9664\u67d0\u4e2a\u5143\u7d20\u4ec5\u51fa\u73b0\u00a0\u4e00\u6b21\u00a0\u5916\uff0c\u5176\u4f59\u6bcf\u4e2a\u5143\u7d20\u90fd\u6070\u51fa\u73b0\u00a0\u4e09\u6b21 \u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u90a3\u4e2a\u53ea\u51fa\u73b0\u4e86\u4e00\u6b21\u7684\u5143\u7d20\u3002<\/p><p>\u3000\u3000Eg.<\/p><p>\u3000\u3000\u3000\u3000\u8f93\u5165\uff1anums = [0, 1, 0, 1, 0, 1, 99]<\/p><p>\u3000\u3000\u3000\u3000\u8f93\u51fa\uff1a99<\/p><p>\u3000\u3000\u6ce8\uff1a\u5f80\u4e0b\u7684\u5185\u5bb9\uff0c\u9700\u8981\u8bfb\u8005\u5bf9\u6570\u5b57\u7535\u8def\u8bbe\u8ba1\u6709\u4e00\u5b9a\u7684\u57fa\u7840\u3002<\/p><p>\u3000\u3000\u5229\u7528\u4e0a\u9762\u4e24\u9898\u7684\u7ecf\u9a8c\uff0c\u6211\u4eec\u7b2c\u4e00\u60f3\u6cd5\u5fc5\u7136\u662f\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u8fdb\u884c\u76f8\u6d88\u2026\u2026\u663e\u7136\u662f\u4e0d\u53ef\u884c\u7684\uff0c\u56e0\u4e3a\u5f02\u6216\u8fd0\u7b97\u53ea\u80fd\u533a\u522b\u5076\u6570\u548c\u5947\u6570\u6b21\u7684\u5143\u7d20\u3002\u90a3\u6211\u4eec\u5982\u4f55\u533a\u522b\u90fd\u662f\u5947\u6570\u6b21\u7684\u5143\u7d20\u5462\uff1f<\/p><p>\u3000\u3000\u5176\u5b9e\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u6d88\u9664\u51fa\u73b0\u5076\u6570\u6b21\u7684\u6570\u5b57\uff0c\u548c\u4e8c\u8fdb\u5236\u7684\u8fdb\u4f4d\u6709\u4e9b\u76f8\u4f3c\u3002\u4e00\u4e2a\u6570\u5b57\u51fa\u73b0\u4e24\u6b21\uff0c\u5c31\u4f1a\u56e0\u4e3a\u5f02\u6216\u76f8\u6d88\uff0c\u65e21 ^ 1 = 0\uff1b\u800c\u4e8c\u8fdb\u5236\u5219\u662f1 + 1 = (1)0\uff0c\u53ea\u662f\u4e8c\u8fdb\u5236\u4e2d\u6211\u4eec\u53ea\u5bf9\u56fa\u5b9a\u4e00\u4f4d\u8fdb\u5236\u8fdb\u884c\u5904\u7406\u3002<\/p><p>\u3000\u3000\u90a3\u4e48\u5bf9\u4e8e\u8fd9\u4e00\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u6784\u5efa\u51fa\u4e00\u79cd\u65b0\u7684\u4e8c\u5143\u8fd0\u7b97\u65b9\u5f0f\uff0c\u4f7f\u5f97\u51fa\u73b03\u6b21\u7684\u6570\u76f8\u6d88\u4e3a0\uff0c\u800c\u4fdd\u7559\u51fa\u73b01\u6b21\u7684\u6570\u5b57\u3002\u7c7b\u4f3c\u4e8e\u4e09\u8fdb\u5236\uff0c1 + 1 + 1 = (1)0\uff0c\u4f46\u8ba1\u7b97\u673a\u5e95\u5c42\u4ecd\u662f\u4f7f\u7528\u4e8c\u8fdb\u5236\u8868\u793a\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u591a\u4e00\u4e2a\u6570\u52a0\u4ee5\u8f85\u52a9\uff0c\u4e3a\u4e86\u65b9\u4fbf\u540e\u7eed\u8868\u8fbe\uff0c\u8fd9\u4e24\u4e2a\u6570\u6211\u8bbe\u4e3ax\u548cy\uff0cx\u548cy\u8868\u8fbe\u76843\u8fdb\u5236\u6570\u6211\u8bbe\u4e3aR\uff0c\u5e76\u4e14\u5177\u6709\u4ee5\u4e0b\u89c4\u5f8b\uff1a<\/p><p>\u3000\u3000\u3000\u3000R = 0\u65f6\uff0cx = 0\uff0cy = 0<\/p><p>\u3000\u3000\u3000\u3000R = 1\u65f6\uff0cx = 0\uff0cy = 1<\/p><p>\u3000\u3000\u3000\u3000R = 2\u65f6\uff0cx = 1\uff0cy = 0<\/p><p>\u3000\u3000\u5047\u8bbe\u6211\u4eec\u9700\u8981\u5bfb\u627e\u7684\u6570\u4e3ares\uff0c\u90a3\u4e48res\u9996\u6b21\u51fa\u73b0\u65f6\uff0cR = 1\uff1b\u7b2c\u4e8c\u6b21\u51fa\u73b0\u65f6\uff0cR = 2\uff1b\u7b2c\u4e09\u6b21\u51fa\u73b0\u65f6\uff0cR = 0\u3002<\/p><p>\u3000\u3000\u7efc\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u83b7\u5f97\u4ee5\u4e0b\u771f\u503c\u8868\uff1a<\/p><table style=\"height: 427px;\" width=\"1723\"><tbody><tr><td width=\"92\"><p style=\"text-align: center;\">x<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>y<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>res<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>\u65b0\u7684x<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>\u65b0\u7684y<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>R<\/p><\/td><\/tr><tr><td width=\"92\"><p style=\"text-align: center;\">0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><\/tr><tr><td width=\"92\"><p style=\"text-align: center;\">0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>1<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>1<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>1<\/p><\/td><\/tr><tr><td style=\"text-align: center;\" width=\"92\"><p>1<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>1<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td width=\"92\"><p style=\"text-align: center;\">2<\/p><\/td><\/tr><tr><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>1<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>1<\/p><\/td><td width=\"92\"><p style=\"text-align: center;\">1<\/p><\/td><\/tr><tr><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>1<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>1<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>1<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td width=\"92\"><p style=\"text-align: center;\">2<\/p><\/td><\/tr><tr><td style=\"text-align: center;\" width=\"92\"><p>1<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>1<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td style=\"text-align: center;\" width=\"92\"><p>0<\/p><\/td><td width=\"92\"><p style=\"text-align: center;\">0<\/p><\/td><\/tr><\/tbody><\/table><p>\u3000\u3000\u8fdb\u800c\u5199\u51fax\u548cy\u5206\u522b\u5bf9\u5e94\u7684\u903b\u8f91\u8868\u8fbe\u5f0f\uff08\u7f16\u7a0b\u8bed\u8a00\u8868\u8fbe\uff0c\u6ca1\u6709\u4f7f\u7528\u4ee3\u6570\u6cd5\u8fdb\u884c\u7b80\u5316\uff09\uff1a<\/p><p>\u3000\u3000\u3000\u3000x = (x &amp; ~y &amp; ~res) | (~x &amp; y &amp; res)<\/p><p>\u3000\u3000\u3000\u3000y = (~x &amp; y &amp; ~res) | (~x &amp; ~y &amp; res)<\/p><p>\u3000\u3000\u7531\u6b64\uff0c\u5f53\u6211\u4eec\u5bf9\u6570\u7ec4\u4e2d\u6240\u6709\u7684\u5143\u7d20\u4f5c\u5b8c\u5904\u7406\u540e\uff0cx\u5fc5\u7136\u4e3a0\uff0cy\u5219\u662f\u51fa\u73b01\u6b21\u7684\u6570\uff0c\u6240\u4ee5\u6211\u4eec\u8fd4\u56dey\u5373\u53ef\u3002\u9898\u5916\u8bdd\uff0c\u82e5\u9898\u76ee\u4e2d\u7684\u76ee\u6807\u6570\u662f\u51fa\u73b0\u4e862\u6b21\uff0c\u65e2R = 2\uff0c\u6b64\u65f6x = 1\uff0cy = 0\uff0c\u6b64\u65f6\u6211\u4eec\u8fd4\u56de\u7684\u5e94\u8be5\u662fx\u3002<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b893b13 elementor-widget elementor-widget-code-highlight\" data-id=\"b893b13\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp>int singleNumber(int[] nums) {\r\n    int x = 0, y = 0;\r\n\r\n    for (int num : nums) {\r\n        \/\/ \u5148\u8fd0\u7b97\uff0c\u7ed3\u679c\u5b58\u50a8\u81f3\u4e34\u65f6\u53d8\u91cf\u4e2d\uff0c\u518d\u8d4b\u503c\r\n        int tempX = (x & ~y & ~num) | (~x & y & num);\r\n        int tempY = (~x & y & ~num) | (~x & ~y & num);\r\n\r\n        x = tempX;\r\n        y = tempY;\r\n    }\r\n\r\n    return y;\r\n}<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>\u4f4d\u8fd0\u7b97\u89c4\u5f8b\u4e0e\u76f8\u5173\u9898\u89e3 \u524d\u8a00 \u4f4d\u8fd0\u7b97\u662f\u8ba1\u7b97\u673a\u4e2d\u6548\u7387\u6700\u9ad8\u7684\u4e00\u79cd\u8fd0\u7b97\u65b9\u5f0f\uff0c\u82e5\u80fd\u5c06\u539f\u6765\u7684\u8fd0\u7b97\u901a\u8fc7\u4f4d\u8fd0\u7b97\u5b9e\u73b0\uff0c\u5c06\u4f1a\u5927\u5927\u63d0 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.xinot.icu\/?p=1475\"> <span class=\"screen-reader-text\">\u4f4d\u8fd0\u7b97\u89c4\u5f8b\u4e0e\u76f8\u5173\u9898\u89e3<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":1476,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-1475","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-algorithm"],"_links":{"self":[{"href":"https:\/\/www.xinot.icu\/index.php?rest_route=\/wp\/v2\/posts\/1475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xinot.icu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xinot.icu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xinot.icu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xinot.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1475"}],"version-history":[{"count":30,"href":"https:\/\/www.xinot.icu\/index.php?rest_route=\/wp\/v2\/posts\/1475\/revisions"}],"predecessor-version":[{"id":1578,"href":"https:\/\/www.xinot.icu\/index.php?rest_route=\/wp\/v2\/posts\/1475\/revisions\/1578"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.xinot.icu\/index.php?rest_route=\/wp\/v2\/media\/1476"}],"wp:attachment":[{"href":"https:\/\/www.xinot.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xinot.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xinot.icu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}