Skip to content

Commit 224b15e

Browse files
author
Dream
committed
[update] 665
1 parent 4d1c861 commit 224b15e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
|684|[Redundant Connection](https://leetcode.com/problems/redundant-connection/) | |Medium|
7474
|674|[Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence/) | |Easy|
7575
|671|[Second Minimum Node In a Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree/) | |Easy|
76-
|665|[Non-decreasing Array](https://leetcode.com/problems/non-decreasing-array/) | |Easy|
76+
|665|[Non-decreasing Array](https://leetcode.com/problems/non-decreasing-array/) | [Java_dream](./algorithms/nonDecreasingArray/NonDecreasingArray.java) |Easy|
7777
|662|[Maximum Width of Binary Tree](https://leetcode.com/problems/maximum-width-of-binary-tree/) | |Medium|
7878
|661|[Image Smoother](https://leetcode.com/problems/image-smoother/) | |Easy|
7979
|655|[Print Binary Tree](https://leetcode.com/problems/print-binary-tree/) | |Medium|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @author Dream
3+
*/
4+
public class NonDecreasingArray {
5+
public boolean checkPossibility(int[] nums) {
6+
int j = 0;
7+
int length = nums.length;
8+
for (int i = 1; i < length; i++) {
9+
if (i > 1 && i < length - 1 && nums[i - 1] > nums[i + 1] && nums[i-2] > nums[i]) {
10+
return false;
11+
}
12+
if (nums[i] < nums[i - 1]) {
13+
j++;
14+
if (j > 1) {
15+
return false;
16+
}
17+
}
18+
}
19+
return true;
20+
}
21+
}

0 commit comments

Comments
 (0)