Skip to content

Commit

Permalink
auto commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CyC2018 committed Feb 22, 2018
1 parent 064e1ed commit 17ef716
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions notes/Leetcode 题解.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,7 @@ public boolean canPlaceFlowers(int[] flowerbed, int n) {

题目描述:判断一个数组能不能只修改一个数就成为非递减数组。

在 nums[i] < nums[i - 1] 的情况下,会优先考虑令 nums[i - 1] = nums[i],因为如果修改 nums[i] = nums[i - 1] 的话,那么 nums[i] 这个数会变大,那么就有可能比 nums[i + 1] 大,我们要尽量使 nums[i] 更小。

但是在 nums[i] < nums[i - 2] 的情况下,只修改 nums[i - 1] 不能令数组成为非递减,只能通过修改 nums[i] = nums[i - 1] 才行。
在出现 nums[i] < nums[i - 1] 时,需要考虑的是应该修改数组的哪个数,使得本次修改能使 i 之前的数组成为非递减数组,并且 **不影响后续的操作**。优先考虑令 nums[i - 1] = nums[i],因为如果修改 nums[i] = nums[i - 1] 的话,那么 nums[i] 这个数会变大,那么就有可能比 nums[i + 1] 大,从而影响了后续操作。还有一个比较特别的情况就是 nums[i] < nums[i - 2],只修改 nums[i - 1] = nums[i] 不能令数组成为非递减,只能通过修改 nums[i] = nums[i - 1] 才行。

```java
public boolean checkPossibility(int[] nums) {
Expand Down

0 comments on commit 17ef716

Please sign in to comment.