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 (English)/非递减数列(English) [non-decreasing-array].html

30 lines
1.1 KiB
HTML
Raw Normal View History

2022-03-27 20:46:41 +08:00
<p>Given an array <code>nums</code> with <code>n</code> integers, your task is to check if it could become non-decreasing by modifying <strong>at most one element</strong>.</p>
<p>We define an array is non-decreasing if <code>nums[i] &lt;= nums[i + 1]</code> holds for every <code>i</code> (<strong>0-based</strong>) such that (<code>0 &lt;= i &lt;= n - 2</code>).</p>
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p><strong class="example">Example 1:</strong></p>
2022-03-27 20:46:41 +08:00
<pre>
<strong>Input:</strong> nums = [4,2,3]
<strong>Output:</strong> true
2023-12-09 18:42:21 +08:00
<strong>Explanation:</strong> You could modify the first 4 to 1 to get a non-decreasing array.
2022-03-27 20:46:41 +08:00
</pre>
2023-12-09 18:42:21 +08:00
<p><strong class="example">Example 2:</strong></p>
2022-03-27 20:46:41 +08:00
<pre>
<strong>Input:</strong> nums = [4,2,1]
<strong>Output:</strong> false
2023-12-09 18:42:21 +08:00
<strong>Explanation:</strong> You cannot get a non-decreasing array by modifying at most one element.
2022-03-27 20:46:41 +08:00
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>4</sup></code></li>
<li><code>-10<sup>5</sup> &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
</ul>