{"id":50883,"date":"2025-08-10T13:54:23","date_gmt":"2025-08-10T05:54:23","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/50883.html"},"modified":"2025-08-10T13:54:23","modified_gmt":"2025-08-10T05:54:23","slug":"%e6%89%be%e4%b8%a4%e4%b8%aa%e5%8d%95%e8%ba%ab%e7%8b%97%ef%bc%88%e7%9a%84%e4%bd%bf%e7%94%a8%e5%ba%94%e7%94%a8%ef%bc%88%e4%bb%8e%e5%8f%b3%e5%90%91%e5%b7%a6%e6%95%b0%e7%ac%ac%e4%b8%80%e4%b8%aa%e4%b8%ba","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/50883.html","title":{"rendered":"\u627e\u4e24\u4e2a\u5355\u8eab\u72d7\uff08^\u7684\u4f7f\u7528\u5e94\u7528)\uff08\u4ece\u53f3\u5411\u5de6\u6570\u7b2c\u4e00\u4e2a\u4e3a 1 \u7684\u6bd4\u7279\u4f4d\uff09"},"content":{"rendered":"<p>\u4e00\u4e2a\u6570\u7ec4\u4e2d\u53ea\u6709\u4e24\u4e2a\u6570\u5b57\u662f\u51fa\u73b0\u4e00\u6b21&#xff0c;\u5176\u4ed6\u6240\u6709\u6570\u5b57\u90fd\u51fa\u73b0\u4e86\u4e24\u6b21\u3002<\/p>\n<p>\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u627e\u51fa\u8fd9\u4e24\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57\u3002<\/p>\n<h4>\u95ee\u9898\u63cf\u8ff0&#xff1a;<\/h4>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4&#xff0c;\u5176\u4e2d\u9664\u4e86\u4e24\u4e2a\u6570\u5b57\u4e4b\u5916&#xff0c;\u6240\u6709\u5176\u4ed6\u6570\u5b57\u90fd\u51fa\u73b0\u4e86\u4e24\u6b21\u3002\u6211\u4eec\u7684\u4efb\u52a1\u662f\u627e\u51fa\u8fd9\u4e24\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57\u3002<\/p>\n<p>\u4f8b\u5982&#xff0c;\u7ed9\u5b9a\u6570\u7ec4&#xff1a;<\/p>\n<p>csharp[1, 2, 3, 4, 5, 1, 2, 3, 4, 6] <\/p>\n<p>\u5176\u4e2d&#xff0c;5 \u548c 6 \u53ea\u51fa\u73b0\u4e86\u4e00\u6b21&#xff0c;\u5176\u4ed6\u6570\u5b57\u90fd\u51fa\u73b0\u4e86\u4e24\u6b21\u3002\u6211\u4eec\u7684\u76ee\u6807\u662f\u901a\u8fc7\u7f16\u7a0b\u627e\u51fa\u8fd9\u4e24\u4e2a\u6570\u5b57\u3002<\/p>\n<h4>\u89e3\u9898\u601d\u8def&#xff1a;<\/h4>\n<h5>1. \u5229\u7528\u5f02\u6216\u8fd0\u7b97\u7684\u6027\u8d28<\/h5>\n<p>\u6211\u4eec\u53ef\u4ee5\u5229\u7528 \u5f02\u6216\u8fd0\u7b97 \u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u5f02\u6216\u8fd0\u7b97\u6709\u4ee5\u4e0b\u51e0\u4e2a\u91cd\u8981\u7684\u6027\u8d28&#xff1a;<\/p>\n<ul>\n<li>\n<p>a ^ a &#061; 0&#xff1a;\u4e24\u4e2a\u76f8\u540c\u7684\u6570\u5b57\u5f02\u6216&#xff0c;\u7ed3\u679c\u662f0\u3002<\/p>\n<\/li>\n<li>\n<p>a ^ 0 &#061; a&#xff1a;\u4efb\u4f55\u6570\u5b57\u4e0e0\u5f02\u6216&#xff0c;\u7ed3\u679c\u662f\u5b83\u672c\u8eab\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f02\u6216\u8fd0\u7b97\u662f\u4ea4\u6362\u5f8b\u548c\u7ed3\u5408\u5f8b\u7684&#xff0c;\u610f\u5473\u7740 a ^ b ^ c \u4e0e a ^ c ^ b \u7ed3\u679c\u76f8\u540c\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u7531\u4e8e\u6570\u7ec4\u4e2d\u9664\u4e86\u4e24\u4e2a\u6570\u5b57\u5916&#xff0c;\u5176\u5b83\u6570\u5b57\u90fd\u51fa\u73b0\u4e24\u6b21&#xff0c;\u6240\u4ee5\u901a\u8fc7\u5f02\u6216\u8fd0\u7b97&#xff0c;\u6700\u7ec8\u6211\u4eec\u53ef\u4ee5\u5c06\u6240\u6709\u51fa\u73b0\u4e24\u6b21\u7684\u6570\u5b57\u90fd\u6d88\u6389&#xff0c;\u7559\u4e0b\u8fd9\u4e24\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57\u3002<\/p>\n<h5>2. \u4e3a\u4ec0\u4e48\u5f02\u6216\u6240\u6709\u6570\u5b57\u80fd\u5f97\u5230\u6700\u7ec8\u7684\u7ed3\u679c&#xff1f;<\/h5>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u6570\u7ec4 [a, b, c, a, b, c, d, e]&#xff0c;\u5176\u4e2d\u9664\u4e86 d \u548c e \u5916&#xff0c;\u6240\u6709\u6570\u5b57\u90fd\u51fa\u73b0\u4e86\u4e24\u6b21\u3002\u901a\u8fc7\u5f02\u6216\u6240\u6709\u6570\u5b57&#xff0c;\u6211\u4eec\u5f97\u5230\u4ee5\u4e0b\u7ed3\u679c&#xff1a;<\/p>\n<p>nginx<\/p>\n<p>a ^ b ^ c ^ a ^ b ^ c ^ d ^ e &#061; (a ^ a) ^ (b ^ b) ^ (c ^ c) ^ d ^ e <\/p>\n<p>\u7531\u4e8e\u4efb\u4f55\u6570\u5b57\u4e0e\u81ea\u5df1\u5f02\u6216\u7ed3\u679c\u4e3a0&#xff0c;\u6240\u4ee5 (a ^ a) &#061; 0&#xff0c;(b ^ b) &#061; 0&#xff0c;(c ^ c) &#061; 0\u3002\u56e0\u6b64\u6700\u7ec8\u7ed3\u679c\u662f&#xff1a;<\/p>\n<p>0 ^ 0 ^ 0 ^ d ^ e &#061; d ^ e <\/p>\n<p>\u8fd9\u8bf4\u660e\u6700\u7ec8\u7ed3\u679c d ^ e \u662f\u4e24\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57\u5f02\u6216\u7684\u7ed3\u679c\u3002<\/p>\n<h5>3. \u5982\u4f55\u4ece d ^ e \u627e\u5230 d \u548c e&#xff1f;<\/h5>\n<p>d ^ e \u7684\u7ed3\u679c\u544a\u8bc9\u6211\u4eec d \u548c e \u5728\u4e8c\u8fdb\u5236\u4e0a\u6709\u4e0d\u540c\u7684\u67d0\u4e00\u4f4d&#xff08;\u81f3\u5c11\u6709\u4e00\u4f4d\u662f1&#xff09;\u3002\u901a\u8fc7\u5206\u6790 d ^ e \u7684\u7ed3\u679c&#xff0c;\u6211\u4eec\u53ef\u4ee5\u627e\u51fa\u4e00\u4e2a\u4f4d&#xff0c;\u786e\u4fdd d \u548c e \u5728\u8fd9\u4e00\u4f4d\u4e0a\u4e0d\u540c\u3002\u7136\u540e&#xff0c;\u57fa\u4e8e\u8fd9\u4e2a\u4f4d&#xff0c;\u5c06\u6570\u7ec4\u5206\u6210\u4e24\u7ec4&#xff0c;\u5206\u522b\u627e\u51fa d \u548c e\u3002<\/p>\n<h5>4. \u5b9e\u9645\u64cd\u4f5c\u6b65\u9aa4&#xff1a;<\/h5>\n<ul>\n<li>\n<p>\u7b2c\u4e00\u6b65&#xff1a;\u8ba1\u7b97\u6570\u7ec4\u4e2d\u6240\u6709\u6570\u5b57\u7684\u5f02\u6216\u7ed3\u679c&#xff0c;\u5f97\u5230 d ^ e\u3002<\/p>\n<\/li>\n<li>\n<p>\u7b2c\u4e8c\u6b65&#xff1a;\u627e\u5230 d ^ e \u4e2d\u4efb\u610f\u4e00\u4f4d\u4e3a1\u7684\u6bd4\u7279&#xff08;\u8fd9\u662f d \u548c e \u5728\u8be5\u4f4d\u7f6e\u4e0a\u7684\u4e0d\u540c&#xff09;\u3002\u5047\u8bbe\u6211\u4eec\u627e\u5230\u7684\u662f\u7b2c k \u4f4d\u3002<\/p>\n<\/li>\n<li>\n<p>\u7b2c\u4e09\u6b65&#xff1a;\u5c06\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u6570\u5b57\u6839\u636e\u8be5\u4f4d\u662f\u5426\u4e3a1\u5206\u4e3a\u4e24\u7ec4&#xff1a;\u4e00\u7ec4\u662f\u8be5\u4f4d\u4e3a1\u7684\u6570\u5b57&#xff0c;\u53e6\u4e00\u7ec4\u662f\u8be5\u4f4d\u4e3a0\u7684\u6570\u5b57\u3002<\/p>\n<\/li>\n<li>\n<p>\u7b2c\u56db\u6b65&#xff1a;\u5206\u522b\u5bf9\u8fd9\u4e24\u7ec4\u6570\u5b57\u505a\u5f02\u6216\u64cd\u4f5c&#xff0c;\u6700\u7ec8\u5f97\u5230 d \u548c e\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>\u8be6\u7ec6\u6b65\u9aa4\u548c\u4ee3\u7801\u5b9e\u73b0&#xff1a;<\/h4>\n<h5>\u7b2c\u4e00\u6b65&#xff1a;\u8ba1\u7b97\u6240\u6709\u6570\u5b57\u7684\u5f02\u6216\u7ed3\u679c<\/h5>\n<p>\u6211\u4eec\u9996\u5148\u5bf9\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u6570\u5b57\u8fdb\u884c\u5f02\u6216\u64cd\u4f5c&#xff0c;\u5f97\u5230 d ^ e\u3002<\/p>\n<p><span style=\"color:#4da8ee\">for (int i &#061; 0; i &lt; n; i&#043;&#043;)<\/span><\/p>\n<p><span style=\"color:#4da8ee\">{<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 xorResult ^&#061; arr[i];<\/span><\/p>\n<p><span style=\"color:#4da8ee\">\u00a0}<\/span><\/p>\n<h5>\u7b2c\u4e8c\u6b65&#xff1a;\u627e\u5230\u4e0d\u540c\u7684\u6bd4\u7279\u4f4d<\/h5>\n<p>\u63a5\u7740&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 d ^ e \u7684\u7ed3\u679c\u627e\u5230 d \u548c e \u5728\u67d0\u4e00\u4f4d\u4e0a\u7684\u5dee\u5f02\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 d ^ e \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u6765\u627e\u5230\u8fd9\u4e00\u4f4d&#xff1a;d ^ e &amp; (-d ^ e)\u3002<\/p>\n<p><span style=\"color:#4da8ee\">int rightmostBit &#061; xorResult &amp; (-xorResult); <\/span><span style=\"color:#ff9900\">\/\/ \u83b7\u53d6\u6700\u53f3\u8fb9\u7684 1 \u4f4d<\/span><br \/>\n\u8fd9\u4e00\u884c\u4ee3\u7801\u5728\u4f4d\u8fd0\u7b97\u4e2d\u975e\u5e38\u6709\u7528&#xff0c;\u5b83\u7684\u76ee\u7684\u662f \u63d0\u53d6 xorResult \u4e2d\u6700\u53f3\u8fb9\u7684 1 \u4f4d&#xff0c;\u8fd9\u5728\u540e\u7eed\u7684\u6b65\u9aa4\u4e2d\u5e2e\u52a9\u6211\u4eec\u5c06\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u5206\u4e3a\u4e24\u7ec4&#xff0c;\u4ece\u800c\u627e\u51fa\u4e24\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57\u3002<\/p>\n<h5>\u4e3a\u4ec0\u4e48\u9700\u8981\u63d0\u53d6\u6700\u53f3\u8fb9\u7684 1 \u4f4d&#xff1f;<\/h5>\n<p>\u901a\u8fc7 xorResult&#xff0c;\u6211\u4eec\u5df2\u7ecf\u77e5\u9053\u6570\u7ec4\u4e2d\u6709\u4e24\u4e2a\u6570\u5b57 d \u548c e \u53ea\u51fa\u73b0\u4e00\u6b21&#xff0c;\u5176\u4f59\u7684\u6570\u5b57\u90fd\u6210\u5bf9\u51fa\u73b0&#xff0c;\u5f02\u6216\u7684\u7ed3\u679c\u662f\u8fd9\u4e24\u4e2a\u6570\u5b57\u7684\u5f02\u6216\u3002\u7531\u4e8e\u8fd9\u4e24\u4e2a\u6570\u5b57\u4e00\u5b9a\u5728\u67d0\u4e9b\u6bd4\u7279\u4f4d\u4e0a\u662f\u4e0d\u540c\u7684&#xff0c;\u5229\u7528\u8fd9\u4e00\u70b9&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e24\u4e2a\u6570\u5b57\u5206\u5230\u4e0d\u540c\u7684\u7ec4\u4e2d\u3002\u4e3a\u4e86\u5206\u7ec4&#xff0c;\u6211\u4eec\u9700\u8981\u627e\u51fa xorResult \u4e2d\u67d0\u4e00\u4f4d\u4e0a\u7684\u5dee\u5f02&#xff0c;\u800c\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u5c31\u662f\u627e\u5230 \u6700\u53f3\u8fb9\u7684 1 \u4f4d\u3002<\/p>\n<h5 style=\"background-color:transparent\">\u5982\u4f55\u7406\u89e3 xorResult &amp; (-xorResult)&#xff1a;<\/h5>\n<li>\n<h6>xorResult \u662f\u8fd9\u4e24\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57\u7684\u5f02\u6216\u7ed3\u679c\u3002<\/h6>\n<p>\u00a0 \u00a0 \u00a0 \u5047\u8bbe xorResult \u7684\u503c\u4e3a 6&#xff0c;\u4e8c\u8fdb\u5236\u662f 0110\u3002<\/li>\n<li>\n<h6>&#8211; xorResult \u53d6\u7684\u662f xorResult \u7684 \u4e8c\u8fdb\u5236\u8865\u7801&#xff1a;<\/h6>\n<ul>\n<li>\n<p>\u5728\u8ba1\u7b97\u673a\u4e2d&#xff0c;\u8d1f\u6570\u662f\u901a\u8fc7\u8865\u7801\u8868\u793a\u7684\u3002\u8865\u7801\u662f\u53d6\u53cd\u52a0 1\u3002\u4f8b\u5982&#xff0c;6 \u7684\u4e8c\u8fdb\u5236\u662f 0110&#xff0c;\u5b83\u7684\u8865\u7801\u662f&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u53d6\u53cd&#xff1a;0110 -&gt; 1001<\/p>\n<\/li>\n<li>\n<p>\u52a0 1&#xff1a;1001 &#043; 1 &#061; 1010<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6240\u4ee5&#xff0c;-6 \u7684\u4e8c\u8fdb\u5236\u662f 1010\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<h6>xorResult &amp; (-xorResult)&#xff1a;<\/h6>\n<ul>\n<li>\n<p>\u5bf9 xorResult \u548c -xorResult \u8fdb\u884c\u6309\u4f4d\u4e0e\u8fd0\u7b97&#xff0c;\u53ef\u4ee5\u63d0\u53d6\u51fa xorResult \u4e2d\u6700\u53f3\u8fb9\u7684 1 \u4f4d\u3002&#xff08;\u662f\u6307\u5728\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u4e2d&#xff0c;\u4ece\u53f3\u5411\u5de6\u6570\u7b2c\u4e00\u4e2a\u4e3a 1 \u7684\u6bd4\u7279\u4f4d\u3002&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u4e3a\u4ec0\u4e48\u5462&#xff1f;\u56e0\u4e3a&#xff1a;<\/p>\n<ul>\n<li>\n<p>xorResult \u4e2d\u7684 1 \u4f4d&#xff0c;\u5728\u8865\u7801 -xorResult \u4e2d\u4f1a\u6709\u4e00\u4e2a\u5bf9\u5e94\u7684 1 \u4f4d&#xff08;\u8865\u7801\u8868\u793a\u662f\u53d6\u53cd\u52a0 1&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u6309\u4f4d\u4e0e\u8fd0\u7b97\u53ea\u4f1a\u4fdd\u7559\u8fd9\u4e9b\u5bf9\u5e94\u4f4d\u7f6e\u4e0a\u7684 1&#xff0c;\u5176\u4ed6\u4f4d\u7f6e\u4f1a\u88ab\u7f6e\u4e3a 0\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u4e3e\u4e2a\u4f8b\u5b50&#xff1a;<\/p>\n<p>\u5728\u8ba1\u7b97\u673a\u4e2d&#xff0c;\u8d1f\u6570\u662f\u901a\u8fc7 \u8865\u7801&#xff08;Two&#039;s Complement&#xff09;\u8868\u793a\u7684\u3002\u8d1f\u6570\u7684\u8865\u7801\u8868\u793a\u6cd5\u662f\u5c06\u5176\u5bf9\u5e94\u7684\u6b63\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u53d6\u53cd\u540e\u52a0 1\u3002<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0<span style=\"color:#ff9900\"> \u00a00010 \/\/ 2<\/span><\/p>\n<ul>\n<li>\n<p>\u5047\u8bbe xorResult &#061; 6&#xff0c;\u5b83\u7684\u4e8c\u8fdb\u5236\u662f 0110\u3002<\/p>\n<\/li>\n<li>\n<p>-xorResult &#061; -6&#xff0c;\u5b83\u7684\u4e8c\u8fdb\u5236\u662f 1010\u3002<\/p>\n<\/li>\n<li>\n<p>\u6309\u4f4d\u4e0e\u8fd0\u7b97&#xff1a;<\/p>\n<p><span>\u00a0<\/span><span style=\"color:#ff9900\">0110 \/\/ 6\u00a0&amp; 1010 \/\/ -6<\/span> <span>\u00a0<\/span><\/p>\n<\/li>\n<li>\n<p>\u7ed3\u679c\u662f 2&#xff0c;\u4e8c\u8fdb\u5236\u4e3a 0010\u3002\u8fd9\u5c31\u662f xorResult \u4e2d \u6700\u53f3\u8fb9\u7684 1 \u4f4d \u6240\u5bf9\u5e94\u7684\u503c\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<p><span style=\"color:#4da8ee\">\u00a0 \u00a0 \u00a0 \u00a0 int num1 &#061; 0, num2 &#061; 0;<\/span><\/p>\n<h5>\u7b2c\u4e09\u6b65&#xff1a;\u6839\u636e\u8be5\u4f4d\u5206\u7ec4<\/h5>\n<p>xorResult \u662f\u4e24\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57\u5f02\u6216\u7684\u7ed3\u679c&#xff0c;\u5b83\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u81f3\u5c11\u6709\u4e00\u4e2a\u4f4d\u662f\u4e0d\u540c\u7684\u3002\u6211\u4eec\u9009\u62e9 rightmostBit \u8fd9\u4e2a\u6bd4\u7279\u4f4d&#xff0c;\u662f\u56e0\u4e3a\u5b83\u662f d \u548c e&#xff08;\u90a3\u4e24\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57&#xff09;\u4e4b\u95f4\u7684\u4e00\u4e2a\u4e0d\u540c\u7684\u6bd4\u7279\u4f4d\u3002<\/p>\n<p>\u5229\u7528\u8be5\u4f4d\u5206\u7ec4&#xff0c;\u5206\u4e3a\u4e24\u7ec4&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e00\u7ec4\u662f\u8be5\u4f4d\u4e3a1\u7684\u6570\u5b57\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e00\u7ec4\u662f\u8be5\u4f4d\u4e3a0\u7684\u6570\u5b57\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6211\u4eec\u5c06\u6574\u4e2a\u6570\u7ec4\u7684\u5143\u7d20\u5206\u4e3a\u4e24\u7ec4&#xff1a;\u4e00\u7ec4\u662f\u8be5\u6bd4\u7279\u4f4d\u4e3a1\u7684\u6570\u5b57&#xff0c;\u53e6\u4e00\u7ec4\u662f\u8be5\u6bd4\u7279\u4f4d\u4e3a0\u7684\u6570\u5b57\u3002\u6211\u4eec\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e2a\u5206\u7ec4&#xff0c;\u5c06\u4e24\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57\u5206\u522b\u5f52\u5230\u4e0d\u540c\u7684\u7ec4\u91cc\u3002&#xff08;\u6bcf\u4e00\u7ec4\u53ea\u6709\u4e00\u4e2a&#xff09;<br \/>\n\u00a0 \u00a0<span style=\"color:#4da8ee\"> for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 if (arr[i] &amp; rightmostBit) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 num1 ^&#061; arr[i]; <\/span><span style=\"color:#ff9900\">\/\/ \u8be5\u6bd4\u7279\u4f4d\u4e3a 1 \u7684\u6570\u5b57<\/span><br \/>\n<span style=\"color:#4da8ee\">\u00a0 \u00a0 \u00a0 \u00a0 } else {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 num2 ^&#061; arr[i]; <\/span><span style=\"color:#ff9900\">\/\/ \u8be5\u6bd4\u7279\u4f4d\u4e3a 0 \u7684\u6570\u5b57<\/span><br \/>\n<span style=\"color:#4da8ee\">\u00a0 \u00a0 \u00a0 \u00a0 }<br \/>\n\u00a0 \u00a0 }<\/span><\/p>\n<h5>\u7b2c\u56db\u6b65&#xff1a;\u5bf9\u4e24\u7ec4\u8fdb\u884c\u5f02\u6216<\/h5>\n<p>\u5bf9\u8fd9\u4e24\u7ec4\u6570\u5b57\u5206\u522b\u8fdb\u884c\u5f02\u6216\u64cd\u4f5c&#xff0c;\u6700\u7ec8\u7ed3\u679c\u5206\u522b\u5c31\u662f\u6211\u4eec\u8981\u627e\u7684\u4e24\u4e2a\u6570\u5b57\u3002<\/p>\n<p><span style=\"color:#4da8ee\">\u00a0printf(&#034;The two numbers that appear only once are: %d and %d\\\\n&#034;, num1, num2);<\/span><\/p>\n<h5><span style=\"color:#0d0016\">\u4e3b\u51fd\u6570<\/span><\/h5>\n<p><span style=\"color:#4da8ee\">int main() {<br \/>\n\u00a0 \u00a0 int arr[] &#061; {1, 2, 3, 4, 5, 1, 2, 3, 4, 6};<br \/>\n\u00a0 \u00a0 int n &#061; sizeof(arr) \/ sizeof(arr[0]);<br \/>\n\u00a0 \u00a0\u00a0findTwoSingleNumbers(arr, n);<br \/>\n\u00a0 \u00a0 return 0;<br \/>\n}<\/span><\/p>\n<h3>\u8be6\u7ec6\u51fd\u6570<\/h3>\n<p>#include &lt;stdio.h&gt;<\/p>\n<p>void findTwoSingleNumbers(int arr[], int n) {<br \/>\n\u00a0 \u00a0 int xorResult &#061; 0;<br \/>\n\u00a0 \u00a0\u00a0<br \/>\n\u00a0 \u00a0 \/\/ \u7b2c\u4e00\u6b65&#xff1a;\u8ba1\u7b97\u6240\u6709\u6570\u5b57\u7684\u5f02\u6216\u7ed3\u679c<br \/>\n\u00a0 \u00a0 for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 xorResult ^&#061; arr[i];<br \/>\n\u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 \/\/ \u7b2c\u4e8c\u6b65&#xff1a;\u627e\u5230\u4e00\u4e2a\u6bd4\u7279\u4f4d&#xff0c;\u4f7f\u5f97\u8be5\u4f4d\u5728\u4e24\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57\u4e4b\u95f4\u4e0d\u540c<br \/>\n\u00a0 \u00a0 int rightmostBit &#061; xorResult &amp; (-xorResult); \/\/ \u83b7\u53d6\u6700\u53f3\u8fb9\u7684 1 \u4f4d<br \/>\n\u00a0 \u00a0\u00a0<br \/>\n\u00a0 \u00a0 int num1 &#061; 0, num2 &#061; 0;<br \/>\n\u00a0 \u00a0\u00a0<br \/>\n\u00a0 \u00a0 \/\/ \u7b2c\u4e09\u6b65&#xff1a;\u5c06\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u5206\u4e3a\u4e24\u7ec4&#xff0c;\u6839\u636e\u8be5\u6bd4\u7279\u4f4d\u4e3a 1 \u6216 0<br \/>\n\u00a0 \u00a0 for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 if (arr[i] &amp; rightmostBit) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 num1 ^&#061; arr[i]; \/\/ \u8be5\u6bd4\u7279\u4f4d\u4e3a 1 \u7684\u6570\u5b57<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 } else {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 num2 ^&#061; arr[i]; \/\/ \u8be5\u6bd4\u7279\u4f4d\u4e3a 0 \u7684\u6570\u5b57<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 }<br \/>\n\u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 \/\/ \u8f93\u51fa\u7ed3\u679c<br \/>\n\u00a0 \u00a0 printf(&#034;The two numbers that appear only once are: %d and %d\\\\n&#034;, num1, num2);<br \/>\n}<\/p>\n<p>int main() {<br \/>\n\u00a0 \u00a0 int arr[] &#061; {1, 2, 3, 4, 5, 1, 2, 3, 4, 6};<br \/>\n\u00a0 \u00a0 int n &#061; sizeof(arr) \/ sizeof(arr[0]);<br \/>\n\u00a0 \u00a0\u00a0<br \/>\n\u00a0 \u00a0 findTwoSingleNumbers(arr, n);<br \/>\n\u00a0 \u00a0\u00a0<br \/>\n\u00a0 \u00a0 return 0;<br \/>\n}<\/p>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb631\u6b21\uff0c\u70b9\u8d5e27\u6b21\uff0c\u6536\u85cf15\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u4e00\u79cd\u5229\u7528\u4f4d\u8fd0\u7b97\u9ad8\u6548\u627e\u51fa\u6570\u7ec4\u4e2d\u4ec5\u51fa\u73b0\u4e00\u6b21\u7684\u4e24\u4e2a\u6570\u5b57\u7684\u65b9\u6cd5\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[174],"topic":[],"class_list":["post-50883","post","type-post","status-publish","format-standard","hentry","category-server","tag-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u627e\u4e24\u4e2a\u5355\u8eab\u72d7\uff08^\u7684\u4f7f\u7528\u5e94\u7528)\uff08\u4ece\u53f3\u5411\u5de6\u6570\u7b2c\u4e00\u4e2a\u4e3a 1 \u7684\u6bd4\u7279\u4f4d\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/50883.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u627e\u4e24\u4e2a\u5355\u8eab\u72d7\uff08^\u7684\u4f7f\u7528\u5e94\u7528)\uff08\u4ece\u53f3\u5411\u5de6\u6570\u7b2c\u4e00\u4e2a\u4e3a 1 \u7684\u6bd4\u7279\u4f4d\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb631\u6b21\uff0c\u70b9\u8d5e27\u6b21\uff0c\u6536\u85cf15\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u4e00\u79cd\u5229\u7528\u4f4d\u8fd0\u7b97\u9ad8\u6548\u627e\u51fa\u6570\u7ec4\u4e2d\u4ec5\u51fa\u73b0\u4e00\u6b21\u7684\u4e24\u4e2a\u6570\u5b57\u7684\u65b9\u6cd5\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/50883.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-10T05:54:23+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/50883.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/50883.html\",\"name\":\"\u627e\u4e24\u4e2a\u5355\u8eab\u72d7\uff08^\u7684\u4f7f\u7528\u5e94\u7528)\uff08\u4ece\u53f3\u5411\u5de6\u6570\u7b2c\u4e00\u4e2a\u4e3a 1 \u7684\u6bd4\u7279\u4f4d\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-10T05:54:23+00:00\",\"dateModified\":\"2025-08-10T05:54:23+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/50883.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/50883.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/50883.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u627e\u4e24\u4e2a\u5355\u8eab\u72d7\uff08^\u7684\u4f7f\u7528\u5e94\u7528)\uff08\u4ece\u53f3\u5411\u5de6\u6570\u7b2c\u4e00\u4e2a\u4e3a 1 \u7684\u6bd4\u7279\u4f4d\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u627e\u4e24\u4e2a\u5355\u8eab\u72d7\uff08^\u7684\u4f7f\u7528\u5e94\u7528)\uff08\u4ece\u53f3\u5411\u5de6\u6570\u7b2c\u4e00\u4e2a\u4e3a 1 \u7684\u6bd4\u7279\u4f4d\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/50883.html","og_locale":"zh_CN","og_type":"article","og_title":"\u627e\u4e24\u4e2a\u5355\u8eab\u72d7\uff08^\u7684\u4f7f\u7528\u5e94\u7528)\uff08\u4ece\u53f3\u5411\u5de6\u6570\u7b2c\u4e00\u4e2a\u4e3a 1 \u7684\u6bd4\u7279\u4f4d\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb631\u6b21\uff0c\u70b9\u8d5e27\u6b21\uff0c\u6536\u85cf15\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u4e00\u79cd\u5229\u7528\u4f4d\u8fd0\u7b97\u9ad8\u6548\u627e\u51fa\u6570\u7ec4\u4e2d\u4ec5\u51fa\u73b0\u4e00\u6b21\u7684\u4e24\u4e2a\u6570\u5b57\u7684\u65b9\u6cd5\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/50883.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-10T05:54:23+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/50883.html","url":"https:\/\/www.wsisp.com\/helps\/50883.html","name":"\u627e\u4e24\u4e2a\u5355\u8eab\u72d7\uff08^\u7684\u4f7f\u7528\u5e94\u7528)\uff08\u4ece\u53f3\u5411\u5de6\u6570\u7b2c\u4e00\u4e2a\u4e3a 1 \u7684\u6bd4\u7279\u4f4d\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-10T05:54:23+00:00","dateModified":"2025-08-10T05:54:23+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/50883.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/50883.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/50883.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u627e\u4e24\u4e2a\u5355\u8eab\u72d7\uff08^\u7684\u4f7f\u7528\u5e94\u7528)\uff08\u4ece\u53f3\u5411\u5de6\u6570\u7b2c\u4e00\u4e2a\u4e3a 1 \u7684\u6bd4\u7279\u4f4d\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/50883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=50883"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/50883\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=50883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=50883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=50883"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=50883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}