File tree 2 files changed +22
-1
lines changed
algorithms/nonDecreasingArray
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 73
73
| 684| [ Redundant Connection] ( https://leetcode.com/problems/redundant-connection/ ) | | Medium|
74
74
| 674| [ Longest Continuous Increasing Subsequence] ( https://leetcode.com/problems/longest-continuous-increasing-subsequence/ ) | | Easy|
75
75
| 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|
77
77
| 662| [ Maximum Width of Binary Tree] ( https://leetcode.com/problems/maximum-width-of-binary-tree/ ) | | Medium|
78
78
| 661| [ Image Smoother] ( https://leetcode.com/problems/image-smoother/ ) | | Easy|
79
79
| 655| [ Print Binary Tree] ( https://leetcode.com/problems/print-binary-tree/ ) | | Medium|
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments