1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/交替数字和 [alternating-digit-sum].html
2023-01-23 20:16:24 +08:00

44 lines
1.0 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>n</code><code>n</code> 中的每一位数字都会按下述规则分配一个符号:</p>
<ul>
<li><strong>最高有效位</strong> 上的数字分配到 <strong></strong> 号。</li>
<li>剩余每位上数字的符号都与其相邻数字相反。</li>
</ul>
<p>返回所有数字及其对应符号的和。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>n = 521
<strong>输出:</strong>4
<strong>解释:</strong>(+5) + (-2) + (+1) = 4</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 111
<strong>输出:</strong>1
<strong>解释:</strong>(+1) + (-1) + (+1) = 1
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>n = 886996
<strong>输出:</strong>0
<strong>解释:</strong>(+8) + (-8) + (+6) + (-9) + (+9) + (-6) = 0
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
</ul>
<p>&nbsp;</p>