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)/数组的三角和 [find-triangular-sum-of-an-array].html
2022-04-03 22:51:40 +08:00

42 lines
1.9 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>给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>nums</code>&nbsp;,其中&nbsp;<code>nums[i]</code>&nbsp;<code>0</code>&nbsp;<code>9</code>&nbsp;之间(两者都包含)的一个数字。</p>
<p><code>nums</code>&nbsp;<strong>三角和</strong>&nbsp;是执行以下操作以后最后剩下元素的值:</p>
<ol>
<li><code>nums</code>&nbsp;初始包含&nbsp;<code>n</code>&nbsp;个元素。如果&nbsp;<code>n == 1</code>&nbsp;<strong>终止</strong>&nbsp;操作。否则,<strong>创建</strong>&nbsp;一个新的下标从&nbsp;<strong>0</strong>&nbsp;开始的长度为 <code>n - 1</code>&nbsp;的整数数组&nbsp;<code>newNums</code>&nbsp;</li>
<li>对于满足&nbsp;<code>0 &lt;= i &lt;&nbsp;n - 1</code>&nbsp;的下标&nbsp;<code>i</code>&nbsp;<code>newNums[i]</code> <strong>赋值</strong>&nbsp;&nbsp;<code>(nums[i] + nums[i+1]) % 10</code>&nbsp;<code>%</code>&nbsp;表示取余运算。</li>
<li>&nbsp;<code>newNums</code>&nbsp;<strong>替换</strong> 数组&nbsp;<code>nums</code>&nbsp;</li>
<li>从步骤 1 开始&nbsp;<strong>重复</strong>&nbsp;整个过程。</li>
</ol>
<p>请你返回&nbsp;<code>nums</code>&nbsp;的三角和。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/02/22/ex1drawio.png" style="width: 250px; height: 250px;" /></p>
<pre>
<b>输入:</b>nums = [1,2,3,4,5]
<b>输出:</b>8
<strong>解释:</strong>
上图展示了得到数组三角和的过程。</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>nums = [5]
<b>输出:</b>5
<b>解释:</b>
由于 nums 中只有一个元素,数组的三角和为这个元素自己。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
<li><code>0 &lt;= nums[i] &lt;= 9</code></li>
</ul>