1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/数组元素和与数字和的绝对差 [difference-between-element-sum-and-digit-sum-of-an-array].html
2023-01-23 20:16:24 +08:00

44 lines
1.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个正整数数组 <code>nums</code></p>
<ul>
<li><strong>元素和</strong><code>nums</code> 中的所有元素相加求和。</li>
<li><strong>数字和</strong>&nbsp;<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>&nbsp;</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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 2000</code></li>
<li><code>1 &lt;= nums[i] &lt;= 2000</code></li>
</ul>