mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			33 lines
		
	
	
		
			881 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			881 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<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>示例 2:</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>
 |