1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-12-20 19:03:47 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (English)/连接非零数字并乘以其数字和 I(English) [concatenate-non-zero-digits-and-multiply-by-sum-i].html
2025-12-06 16:04:11 +08:00

47 lines
1.5 KiB
HTML

<p>You are given an integer <code>n</code>.</p>
<p>Form a new integer <code>x</code> by concatenating all the <strong>non-zero digits</strong> of <code>n</code> in their original order. If there are no <strong>non-zero</strong> digits, <code>x = 0</code>.</p>
<p>Let <code>sum</code> be the <strong>sum of digits</strong> in <code>x</code>.</p>
<p>Return an integer representing the value of <code>x * sum</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 10203004</span></p>
<p><strong>Output:</strong> <span class="example-io">12340</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>The non-zero digits are 1, 2, 3, and 4. Thus, <code>x = 1234</code>.</li>
<li>The sum of digits is <code>sum = 1 + 2 + 3 + 4 = 10</code>.</li>
<li>Therefore, the answer is <code>x * sum = 1234 * 10 = 12340</code>.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 1000</span></p>
<p><strong>Output:</strong> <span class="example-io">1</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>The non-zero digit is 1, so <code>x = 1</code> and <code>sum = 1</code>.</li>
<li>Therefore, the answer is <code>x * sum = 1 * 1 = 1</code>.</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 &lt;= n &lt;= 10<sup>9</sup></code></li>
</ul>