{"id":6090,"date":"2020-01-13T21:29:34","date_gmt":"2020-01-14T05:29:34","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=6090"},"modified":"2020-01-14T20:15:59","modified_gmt":"2020-01-15T04:15:59","slug":"leetcode-1317-convert-integer-to-the-sum-of-two-no-zero-integers","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/math\/leetcode-1317-convert-integer-to-the-sum-of-two-no-zero-integers\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 1317. Convert Integer to the Sum of Two No-Zero Integers"},"content":{"rendered":"\n<p>Given an integer&nbsp;<code>n<\/code>. No-Zero integer is a positive integer which&nbsp;<strong>doesn&#8217;t contain any 0<\/strong>&nbsp;in its decimal representation.<\/p>\n\n\n\n<p>Return&nbsp;<em>a list of two integers<\/em>&nbsp;<code>[A, B]<\/code>&nbsp;where:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>A<\/code>&nbsp;and&nbsp;<code>B<\/code>&nbsp;are No-Zero integers.<\/li><li><code>A + B = n<\/code><\/li><\/ul>\n\n\n\n<p>It&#8217;s guarateed that there is at least one valid solution. If there are many valid solutions you can return any of them.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;cryaon:false\"><strong>Input:<\/strong> n = 2\n<strong>Output:<\/strong> [1,1]\n<strong>Explanation:<\/strong> A = 1, B = 1. A + B = n and both A and B don't contain any 0 in their decimal representation.\n<\/pre>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;cryaon:false\"><strong>Input:<\/strong> n = 11\n<strong>Output:<\/strong> [2,9]\n<\/pre>\n\n\n\n<p><strong>Example 3:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;cryaon:false\"><strong>Input:<\/strong> n = 10000\n<strong>Output:<\/strong> [1,9999]\n<\/pre>\n\n\n\n<p><strong>Example 4:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;cryaon:false\"><strong>Input:<\/strong> n = 69\n<strong>Output:<\/strong> [1,68]\n<\/pre>\n\n\n\n<p><strong>Example 5:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;cryaon:false\"><strong>Input:<\/strong> n = 1010\n<strong>Output:<\/strong> [11,999]\n<\/pre>\n\n\n\n<p><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>2 &lt;= n &lt;= 10^4<\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution: Brute Force<\/strong><\/h2>\n\n\n\n<p>Time complexity: O(nlogn)<br>Space complexity: O(1)<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"C++\">\n\/\/ Author: Huahua\nclass Solution {\npublic:\n  vector<int> getNoZeroIntegers(int n) {\n    auto valid = [](int x) {\n      if (!x) return false;\n      while (x) {\n        if (x % 10 == 0) return false;\n        x \/= 10;\n      }\n      return true;\n    };\n    \n    for (int i = 1; i <= n \/ 2; ++i)\n      if (valid(i) &#038;&#038; valid(n - i)) \n        return {i, n - i};\n    return {};\n  }\n};\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Given an integer&nbsp;n. No-Zero integer is a positive integer which&nbsp;doesn&#8217;t contain any 0&nbsp;in its decimal representation. Return&nbsp;a list of two integers&nbsp;[A, B]&nbsp;where: A&nbsp;and&nbsp;B&nbsp;are No-Zero integers.&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[521,222,31,377],"class_list":["post-6090","post","type-post","status-publish","format-standard","hentry","category-math","tag-digits","tag-easy","tag-math","tag-onlogn","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/6090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=6090"}],"version-history":[{"count":3,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/6090\/revisions"}],"predecessor-version":[{"id":6097,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/6090\/revisions\/6097"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=6090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=6090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=6090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}