mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-13 11:21:42 +08:00
add leetcode problem-cn part6
This commit is contained in:
32
算法题(国内版)/problem (Chinese)/各位相加 [add-digits].html
Normal file
32
算法题(国内版)/problem (Chinese)/各位相加 [add-digits].html
Normal file
@@ -0,0 +1,32 @@
|
||||
<p>给定一个非负整数 <code>num</code>,反复将各个位上的数字相加,直到结果为一位数。返回这个结果。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> num =<strong> </strong><code>38</code>
|
||||
<strong>输出:</strong> 2
|
||||
<strong>解释: </strong>各位相加的过程为<strong>:
|
||||
</strong>38 --> 3 + 8 --> 11
|
||||
11 --> 1 + 1 --> 2
|
||||
由于 <code>2</code> 是一位数,所以返回 2。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> num =<strong> </strong>0
|
||||
<strong>输出:</strong> 0</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= num <= 2<sup>31</sup> - 1</code></li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>进阶:</strong>你可以不使用循环或者递归,在 <code>O(1)</code> 时间复杂度内解决这个问题吗?</p>
|
Reference in New Issue
Block a user