{"id":300,"date":"2020-06-19T16:46:56","date_gmt":"2020-06-19T16:46:56","guid":{"rendered":"http:\/\/feellikelearning.com\/?p=300"},"modified":"2020-06-19T16:48:34","modified_gmt":"2020-06-19T16:48:34","slug":"leetcode-415-add-strings-solution","status":"publish","type":"post","link":"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/","title":{"rendered":"\u7b97\u6cd5\u7ec3\u4e60 Leetcode \u529b\u6263 415. Add Strings \u89e3\u6cd5"},"content":{"rendered":"\n<p>\u548c<a href=\"http:\/\/feellikelearning.com\/wp-admin\/post.php?post=297&amp;action=edit\">add <\/a><a href=\"http:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-67-add-binary-solution\/\">binary<\/a>\u57fa\u672c\u4e00\u6837\u3002<\/p>\n\n\n\n<p>\u5173\u952e\u70b9\uff1a<br>\u4ece\u53f3\u8fb9\u5f00\u59cb\u52a0<br>\u628a\u957f\u7684input\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\uff0c\u7ed9\u6700\u5de6\u8fb9\u52a00\u7528\u6765\u8fdb\u4f4d\uff08\u5982\u679c\u9700\u8981\u7684\u8bdd\uff09\uff0c\u6700\u540e\u770b\u8981\u4e0d\u8981\u53bb\u6389<br>python\u91cc\u9762\u8981\u7528ord\uff0cchr \u6765\u505achar\/ascii\u8f6c\u6362<\/p>\n\n\n\n<p>python\u89e3\u6cd5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution(object):\n    def addStrings(self, num1, num2):\n        \"\"\"\n        :type num1: str\n        :type num2: str\n        :rtype: str\n        \"\"\"\n        if num1 is None or len(num1) == 0:\n            return num2\n        if num2 is None or len(num2) == 0:\n            return num1\n        if len(num1) &lt; len(num2):\n            return self.addStrings(num2, num1)\n        n1 = ['0'] + [c for c in num1]\n        n2 = [c for c in num2]\n        i = len(n1) - 1\n        j = len(n2) - 1\n        while i >= 0:\n            if j >= 0:\n                n1[i] = chr(ord(n1[i]) + ord(n2[j]) - ord('0'))\n            if n1[i] > '9':\n                n1[i] = chr(ord(n1[i]) - 10)\n                n1[i - 1] = chr(ord(n1[i - 1]) + 1)\n            i -= 1\n            j -= 1\n        ans = ''.join(n1)\n        if ans[0] == '0':\n            return ans[1:]\n        return ans<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u548cadd binary\u57fa\u672c\u4e00\u6837\u3002 \u5173\u952e\u70b9\uff1a\u4ece\u53f3\u8fb9\u5f00\u59cb\u52a0\u628a\u957f\u7684input\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\uff0c\u7ed9\u6700\u5de6\u8fb9\u52a00\u7528\u6765\u8fdb\u4f4d\uff08\u5982\u679c\u9700\u8981\u7684\u8bdd\uff09\uff0c\u6700\u540e\u770b\u8981\u4e0d\u8981\u53bb\u6389python\u91cc\u9762\u8981\u7528ord\uff0cchr \u6765\u505achar\/ascii\u8f6c\u6362 python\u89e3\u6cd5<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7b97\u6cd5\u7ec3\u4e60 Leetcode \u529b\u6263 415. Add Strings \u89e3\u6cd5 | Feel Like Learning<\/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:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7b97\u6cd5\u7ec3\u4e60 Leetcode \u529b\u6263 415. Add Strings \u89e3\u6cd5 | Feel Like Learning\" \/>\n<meta property=\"og:description\" content=\"\u548cadd binary\u57fa\u672c\u4e00\u6837\u3002 \u5173\u952e\u70b9\uff1a\u4ece\u53f3\u8fb9\u5f00\u59cb\u52a0\u628a\u957f\u7684input\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\uff0c\u7ed9\u6700\u5de6\u8fb9\u52a00\u7528\u6765\u8fdb\u4f4d\uff08\u5982\u679c\u9700\u8981\u7684\u8bdd\uff09\uff0c\u6700\u540e\u770b\u8981\u4e0d\u8981\u53bb\u6389python\u91cc\u9762\u8981\u7528ord\uff0cchr \u6765\u505achar\/ascii\u8f6c\u6362 python\u89e3\u6cd5\" \/>\n<meta property=\"og:url\" content=\"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/\" \/>\n<meta property=\"og:site_name\" content=\"Feel Like Learning\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-19T16:46:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-06-19T16:48:34+00:00\" \/>\n<meta name=\"author\" content=\"feellikelearning\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"feellikelearning\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/\"},\"author\":{\"name\":\"feellikelearning\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"headline\":\"\u7b97\u6cd5\u7ec3\u4e60 Leetcode \u529b\u6263 415. Add Strings \u89e3\u6cd5\",\"datePublished\":\"2020-06-19T16:46:56+00:00\",\"dateModified\":\"2020-06-19T16:48:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/\"},\"wordCount\":12,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/\",\"url\":\"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/\",\"name\":\"\u7b97\u6cd5\u7ec3\u4e60 Leetcode \u529b\u6263 415. Add Strings \u89e3\u6cd5 | Feel Like Learning\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/#website\"},\"datePublished\":\"2020-06-19T16:46:56+00:00\",\"dateModified\":\"2020-06-19T16:48:34+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/feellikelearning.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7b97\u6cd5\u7ec3\u4e60 Leetcode \u529b\u6263 415. Add Strings \u89e3\u6cd5\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/feellikelearning.com\/#website\",\"url\":\"https:\/\/feellikelearning.com\/\",\"name\":\"Feel Like Learning\",\"description\":\"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230\",\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/feellikelearning.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\",\"name\":\"feellikelearning\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"caption\":\"feellikelearning\"},\"logo\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7b97\u6cd5\u7ec3\u4e60 Leetcode \u529b\u6263 415. Add Strings \u89e3\u6cd5 | Feel Like Learning","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:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/","og_locale":"en_US","og_type":"article","og_title":"\u7b97\u6cd5\u7ec3\u4e60 Leetcode \u529b\u6263 415. Add Strings \u89e3\u6cd5 | Feel Like Learning","og_description":"\u548cadd binary\u57fa\u672c\u4e00\u6837\u3002 \u5173\u952e\u70b9\uff1a\u4ece\u53f3\u8fb9\u5f00\u59cb\u52a0\u628a\u957f\u7684input\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\uff0c\u7ed9\u6700\u5de6\u8fb9\u52a00\u7528\u6765\u8fdb\u4f4d\uff08\u5982\u679c\u9700\u8981\u7684\u8bdd\uff09\uff0c\u6700\u540e\u770b\u8981\u4e0d\u8981\u53bb\u6389python\u91cc\u9762\u8981\u7528ord\uff0cchr \u6765\u505achar\/ascii\u8f6c\u6362 python\u89e3\u6cd5","og_url":"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/","og_site_name":"Feel Like Learning","article_published_time":"2020-06-19T16:46:56+00:00","article_modified_time":"2020-06-19T16:48:34+00:00","author":"feellikelearning","twitter_card":"summary_large_image","twitter_misc":{"Written by":"feellikelearning","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/#article","isPartOf":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/"},"author":{"name":"feellikelearning","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"headline":"\u7b97\u6cd5\u7ec3\u4e60 Leetcode \u529b\u6263 415. Add Strings \u89e3\u6cd5","datePublished":"2020-06-19T16:46:56+00:00","dateModified":"2020-06-19T16:48:34+00:00","mainEntityOfPage":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/"},"wordCount":12,"commentCount":0,"publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/","url":"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/","name":"\u7b97\u6cd5\u7ec3\u4e60 Leetcode \u529b\u6263 415. Add Strings \u89e3\u6cd5 | Feel Like Learning","isPartOf":{"@id":"https:\/\/feellikelearning.com\/#website"},"datePublished":"2020-06-19T16:46:56+00:00","dateModified":"2020-06-19T16:48:34+00:00","breadcrumb":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/06\/19\/leetcode-415-add-strings-solution\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/feellikelearning.com\/"},{"@type":"ListItem","position":2,"name":"\u7b97\u6cd5\u7ec3\u4e60 Leetcode \u529b\u6263 415. Add Strings \u89e3\u6cd5"}]},{"@type":"WebSite","@id":"https:\/\/feellikelearning.com\/#website","url":"https:\/\/feellikelearning.com\/","name":"Feel Like Learning","description":"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230","publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/feellikelearning.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a","name":"feellikelearning","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","caption":"feellikelearning"},"logo":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/"},"url":"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/"}]}},"_links":{"self":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/300"}],"collection":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/comments?post=300"}],"version-history":[{"count":3,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/300\/revisions"}],"predecessor-version":[{"id":304,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/300\/revisions\/304"}],"wp:attachment":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/media?parent=300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/categories?post=300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/tags?post=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}