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)/增量元素之间的最大差值 [maximum-difference-between-increasing-elements].html
2022-03-29 12:43:11 +08:00

41 lines
1.6 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> 开始的整数数组 <code>nums</code> ,该数组的大小为 <code>n</code> ,请你计算 <code>nums[j] - nums[i]</code> 能求得的 <strong>最大差值 </strong>,其中 <code>0 &lt;= i &lt; j &lt; n</code><code>nums[i] &lt; nums[j]</code></p>
<p>返回 <strong>最大差值</strong> 。如果不存在满足要求的 <code>i</code><code>j</code> ,返回 <code>-1</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>nums = [7,<em><strong>1</strong></em>,<em><strong>5</strong></em>,4]
<strong>输出:</strong>4
<strong>解释:</strong>
最大差值出现在 i = 1 且 j = 2 时nums[j] - nums[i] = 5 - 1 = 4 。
注意,尽管 i = 1 且 j = 0 时 nums[j] - nums[i] = 7 - 1 = 6 &gt; 4 ,但 i &gt; j 不满足题面要求,所以 6 不是有效的答案。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>nums = [9,4,3,2]
<strong>输出:</strong>-1
<strong>解释:</strong>
不存在同时满足 i &lt; j 和 nums[i] &lt; nums[j] 这两个条件的 i, j 组合。
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>nums = [<em><strong>1</strong></em>,5,2,<em><strong>10</strong></em>]
<strong>输出:</strong>9
<strong>解释:</strong>
最大差值出现在 i = 0 且 j = 3 时nums[j] - nums[i] = 10 - 1 = 9 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>2 &lt;= n &lt;= 1000</code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>