mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你一个正整数数组 <code>nums</code> 。</p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><strong>元素和</strong> 是 <code>nums</code> 中的所有元素相加求和。</li>
 | 
						||
	<li><strong>数字和</strong> 是 <code>nums</code> 中每一个元素的每一数位(重复数位需多次求和)相加求和。</li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p>返回 <strong>元素和</strong> 与 <strong>数字和</strong> 的绝对差。</p>
 | 
						||
 | 
						||
<p><strong>注意:</strong>两个整数 <code>x</code> 和 <code>y</code> 的绝对差定义为 <code>|x - y|</code> 。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>nums = [1,15,6,3]
 | 
						||
<strong>输出:</strong>9
 | 
						||
<strong>解释:</strong>
 | 
						||
nums 的元素和是 1 + 15 + 6 + 3 = 25 。
 | 
						||
nums 的数字和是 1 + 1 + 5 + 6 + 3 = 16 。
 | 
						||
元素和与数字和的绝对差是 |25 - 16| = 9 。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>nums = [1,2,3,4]
 | 
						||
<strong>输出:</strong>0
 | 
						||
<strong>解释:</strong>
 | 
						||
nums 的元素和是 1 + 2 + 3 + 4 = 10 。
 | 
						||
nums 的数字和是 1 + 2 + 3 + 4 = 10 。
 | 
						||
元素和与数字和的绝对差是 |10 - 10| = 0 。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= nums.length <= 2000</code></li>
 | 
						||
	<li><code>1 <= nums[i] <= 2000</code></li>
 | 
						||
</ul>
 |