{"id":2336,"date":"2022-01-24T11:02:01","date_gmt":"2022-01-24T03:02:01","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2336"},"modified":"2022-01-24T11:02:02","modified_gmt":"2022-01-24T03:02:02","slug":"leetcodeday65","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/24\/leetcodeday65\/","title":{"rendered":"leetcodeday65&#8211;\u4e8c\u8fdb\u5236\u6c42\u548c"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e24\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u5b83\u4eec\u7684\u548c\uff08\u7528\u4e8c\u8fdb\u5236\u8868\u793a\uff09\u3002<\/p>\n\n\n\n<p>\u8f93\u5165\u4e3a&nbsp;<strong>\u975e\u7a7a&nbsp;<\/strong>\u5b57\u7b26\u4e32\u4e14\u53ea\u5305\u542b\u6570\u5b57&nbsp;<code>1<\/code>&nbsp;\u548c&nbsp;<code>0<\/code>\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong> a = \"11\", b = \"1\"\n<strong>\u8f93\u51fa:<\/strong> \"100\"<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong> a = \"1010\", b = \"1011\"\n<strong>\u8f93\u51fa:<\/strong> \"10101\"<\/code><\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul><li>\u6bcf\u4e2a\u5b57\u7b26\u4e32\u4ec5\u7531\u5b57\u7b26&nbsp;<code>'0'<\/code>&nbsp;\u6216&nbsp;<code>'1'<\/code>&nbsp;\u7ec4\u6210\u3002<\/li><li><code>1 &lt;= a.length, b.length &lt;= 10^4<\/code><\/li><li>\u5b57\u7b26\u4e32\u5982\u679c\u4e0d\u662f&nbsp;<code>\"0\"<\/code>&nbsp;\uff0c\u5c31\u90fd\u4e0d\u542b\u524d\u5bfc\u96f6\u3002<\/li><\/ul>\n\n\n\n<p>\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=67 lang=python3\r\n#\r\n# &#91;67] \u4e8c\u8fdb\u5236\u6c42\u548c\r\n#\r\n\r\n# @lc code=start\r\nfrom calendar import c\r\n\r\n\r\nclass Solution:\r\n    def addBinary(self,a: str, b: str) -> str:\r\n        def Binary(i,j,carry=0):\r\n            i=int(i)\r\n            j=int(j)\r\n            carry=int(carry)\r\n            carrys=(i+j+carry)\/\/2\r\n            n=(i+j+carry)%2\r\n            return str(n),str(carrys)\r\n        lena=len(a)\r\n        lenb=len(b)\r\n        rev=\"\"\r\n        if lena&lt;lenb:\r\n            c=a\r\n            a=b\r\n            b=c\r\n        carry=0\r\n        lens=max(lena,lenb)\r\n        b=\"0\"*abs(lena-lenb)+b\r\n        for i in range(lens-1,-1,-1):\r\n            #print(a&#91;i],b&#91;i],carry)\r\n            n,carry=Binary(a&#91;i],b&#91;i],carry)\r\n            rev=n+rev\r\n        if carry==\"1\":\r\n             rev=carry+rev\r\n        return rev\r\n\r\n<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-280.png\" alt=\"\" class=\"wp-image-2337\" width=\"431\" height=\"177\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-280.png 645w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-280-300x123.png 300w\" sizes=\"(max-width: 431px) 100vw, 431px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e24\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u5b83\u4eec\u7684\u548c\uff08\u7528\u4e8c\u8fdb\u5236\u8868\u793a\uff09\u3002 \u8f93\u5165\u4e3a&nbsp;\u975e\u7a7a&nbsp;\u5b57\u7b26\u4e32\u4e14\u53ea\u5305\u542b\u6570\u5b57&#038;n &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/24\/leetcodeday65\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday65&#8211;\u4e8c\u8fdb\u5236\u6c42\u548c<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2336"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2336"}],"version-history":[{"count":2,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2336\/revisions"}],"predecessor-version":[{"id":2339,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2336\/revisions\/2339"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2336"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}