{"id":377,"date":"2020-09-26T10:34:22","date_gmt":"2020-09-26T02:34:22","guid":{"rendered":"http:\/\/39.96.58.60\/?p=377"},"modified":"2022-10-18T16:39:35","modified_gmt":"2022-10-18T08:39:35","slug":"leetcode-%e9%9d%a2%e8%af%95%e9%a2%98-05-06-%e6%95%b4%e6%95%b0%e8%bd%ac%e6%8d%a2","status":"publish","type":"post","link":"http:\/\/www.yatenglg.cn\/blog\/?p=377","title":{"rendered":"Leetcode \u9762\u8bd5\u9898 05.06. \u6574\u6570\u8f6c\u6362"},"content":{"rendered":"<p>\u6574\u6570\u8f6c\u6362\u3002\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u786e\u5b9a\u9700\u8981\u6539\u53d8\u51e0\u4e2a\u4f4d\u624d\u80fd\u5c06\u6574\u6570A\u8f6c\u6210\u6574\u6570B\u3002<\/p>\n<p><strong>\u793a\u4f8b1:<\/strong><\/p>\n<pre><strong> \u8f93\u5165<\/strong>\uff1aA = 29 \uff08\u6216\u80050b11101\uff09, B = 15\uff08\u6216\u80050b01111\uff09\n\n<strong> \u8f93\u51fa<\/strong>\uff1a2\n\n<\/pre>\n<p><strong>\u793a\u4f8b2:<\/strong><\/p>\n<pre><strong> \u8f93\u5165<\/strong>\uff1aA = 1\uff0cB = 2\n\n<strong> \u8f93\u51fa<\/strong>\uff1a2\n\n<\/pre>\n<p><strong>\u63d0\u793a:<\/strong><\/p>\n<ol>\n<li>A\uff0cB\u8303\u56f4\u5728[-2147483648, 2147483647]\u4e4b\u95f4<\/li>\n<\/ol>\n<p>**\u96be\u5ea6**: Easy<\/p>\n<p>**\u6807\u7b7e**: \u4f4d\u8fd0\u7b97\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\uff1a44 ms, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8635.20% \u7684\u7528\u6237\n\u5185\u5b58\u6d88\u8017\uff1a13.6 MB, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e86100.00% \u7684\u7528\u6237\n\u89e3\u9898\u601d\u8def\uff1a\n    \u8fd9\u91cc\u51fa\u73b0\u4e86\u4e2a\u5751\uff0c\u4e4b\u524d\u4e00\u76f4\u6ca1\u6ce8\u610f\n    \u539f\u5148\u76f4\u63a5\u5199\u7684  return bin(A ^ B).replace('0b','').count('1')\n    &amp; \u6309\u4f4d\u4e0e\n\n    \u4f46\u4e00\u76f4\u51fa\u9519\uff0c\u540e\u9762\u770b\u89e3\u9898\u53d1\u73b0\uff1a\n    ```\n        \u4e00\u822c\u6765\u8bb2\uff0c\u6574\u5f62\u6570\u5728\u5185\u5b58\u4e2d\u662f\u4ee5 \u8865\u7801 \u7684\u5f62\u5f0f\u5b58\u653e\u7684\uff0c\u8f93\u51fa\u7684\u65f6\u5019\u540c\u6837\u4e5f\u662f\u6309\u7167 \u8865\u7801 \u8f93\u51fa\u7684\u3002\n        \u4f46\u662f\u5728python\u4e2d\uff1a\n            1. \u6574\u5f62\u662f\u4ee5 \u8865\u7801 \u5f62\u5f0f\u5b58\u653e\u7684\uff0c\u8f93\u51fa\u7684\u65f6\u5019\u662f\u6309\u7167 \u4e8c\u8fdb\u5236 \u8868\u793a\u8f93\u51fa\u7684\uff1b\n            2. \u5bf9\u4e8e bin(x)bin(x)bin(x)\uff08xxx \u4e3a \u5341\u8fdb\u5236\u8d1f\u6570\uff09\uff0c\u8f93\u51fa\u7684\u662f\u5b83\u7684\u539f\u7801\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u52a0\u4e0a\u4e00\u4e2a\u8d1f\u53f7\uff0c\u65b9\u4fbf\u67e5\u770b\uff08\u65b9\u4fbf\u4e2a???\uff09\n            3. \u5bf9\u4e8e bin(x)bin(x)bin(x)\uff08xxx \u4e3a \u5341\u516d\u8fdb\u5236\u8d1f\u6570\uff09\uff0c\u8f93\u51fa\u7684\u662f\u5bf9\u5e94\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u3002\n        \u6240\u4ee5\u4e3a\u4e86\u83b7\u5f97\u5341\u8fdb\u5236\u8d1f\u6570\u7684\u8865\u7801\uff0c\u6211\u4eec\u9700\u8981\u624b\u52a8\u5c06\u5176\u548c 0xffffffff \u8fdb\u884c\u4e0e\u64cd\u4f5c\uff0c\u5f97\u5230\u4e00\u4e2a\u5341\u516d\u8fdb\u5236\u6570\uff0c\u518d\u4ea4\u7ed9 bin() \u8f6c\u5316\uff0c\u8fd9\u65f6\u5185\u5b58\u4e2d\u5f97\u5230\u7684\u624d\u662f\u4f60\u60f3\u8981\u7684\u8865\u7801\u3002\n\n        \u4f5c\u8005\uff1az1m\n        \u94fe\u63a5\uff1ahttps:\/\/leetcode-cn.com\/problems\/convert-integer-lcci\/solution\/yi-huo-jie-fa-python-3-c-by-z1m\/\n        \u6765\u6e90\uff1a\u529b\u6263\uff08LeetCode\uff09\n        \u8457\u4f5c\u6743\u5f52\u4f5c\u8005\u6240\u6709\u3002\u5546\u4e1a\u8f6c\u8f7d\u8bf7\u8054\u7cfb\u4f5c\u8005\u83b7\u5f97\u6388\u6743\uff0c\u975e\u5546\u4e1a\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\u3002\n    ```\n\n\"\"\"\nclass Solution:\n    def convertInteger(self, A: int, B: int) -&gt; int:\n        return bin((A &amp; 0xffffffff) ^ (B &amp; 0xffffffff)).replace('0b','').count('1')<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6574\u6570\u8f6c\u6362\u3002\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u786e\u5b9a\u9700\u8981\u6539\u53d8\u51e0\u4e2a\u4f4d\u624d\u80fd\u5c06\u6574\u6570A\u8f6c\u6210\u6574\u6570B\u3002 \u793a\u4f8b1: \u8f93\u5165\uff1aA = 29 \uff08\u6216\u80050b1&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","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\/377"}],"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=377"}],"version-history":[{"count":1,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/377\/revisions"}],"predecessor-version":[{"id":378,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/377\/revisions\/378"}],"wp:attachment":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=377"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}