{"id":9948,"date":"2023-02-13T16:00:21","date_gmt":"2023-02-14T00:00:21","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=9948"},"modified":"2023-02-13T16:01:34","modified_gmt":"2023-02-14T00:01:34","slug":"leetcode-2553-separate-the-digits-in-an-array","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/stack\/leetcode-2553-separate-the-digits-in-an-array\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 2553.\u00a0Separate the Digits in an Array"},"content":{"rendered":"\n<p>Given an array of positive integers\u00a0<code>nums<\/code>, return\u00a0<em>an array\u00a0<\/em><code>answer<\/code><em>\u00a0that consists of the digits of each integer in\u00a0<\/em><code>nums<\/code><em>\u00a0after separating them in\u00a0<strong>the same order<\/strong>\u00a0they appear in\u00a0<\/em><code>nums<\/code>.<\/p>\n\n\n\n<p>To separate the digits of an integer is to get all the digits it has in the same order.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>For example, for the integer&nbsp;<code>10921<\/code>, the separation of its digits is&nbsp;<code>[1,0,9,2,1]<\/code>.<\/li><\/ul>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> nums = [13,25,83,77]\n<strong>Output:<\/strong> [1,3,2,5,8,3,7,7]\n<strong>Explanation:<\/strong> \n- The separation of 13 is [1,3].\n- The separation of 25 is [2,5].\n- The separation of 83 is [8,3].\n- The separation of 77 is [7,7].\nanswer = [1,3,2,5,8,3,7,7]. Note that answer contains the separations in the same order.\n<\/pre>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> nums = [7,1,3,9]\n<strong>Output:<\/strong> [7,1,3,9]\n<strong>Explanation:<\/strong> The separation of each integer in nums is itself.\nanswer = [7,1,3,9].\n<\/pre>\n\n\n\n<p><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>1 &lt;= nums.length &lt;= 1000<\/code><\/li><li><code>1 &lt;= nums[i] &lt;= 10<sup>5<\/sup><\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution: Stack<\/strong><\/h2>\n\n\n\n<p>Time complexity: O(sum(log(nums[i]))<br>Space complexity: O(log(nums[i]))<\/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> separateDigits(vector<int>& nums) {\n    vector<int> ans;\n    for (int n : nums) {\n      stack<int> cur;\n      for (int x = n; x; x \/= 10)\n        cur.push(x % 10);\n      while (!cur.empty())      \n        ans.push_back(cur.top()), cur.pop();\n    }\n    return ans;\n  }\n};\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Given an array of positive integers\u00a0nums, return\u00a0an array\u00a0answer\u00a0that consists of the digits of each integer in\u00a0nums\u00a0after separating them in\u00a0the same order\u00a0they appear in\u00a0nums. To separate&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[407],"tags":[222,180],"class_list":["post-9948","post","type-post","status-publish","format-standard","hentry","category-stack","tag-easy","tag-stack","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/9948","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=9948"}],"version-history":[{"count":3,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/9948\/revisions"}],"predecessor-version":[{"id":9952,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/9948\/revisions\/9952"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=9948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=9948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=9948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}