forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_1909.java
25 lines (24 loc) · 805 Bytes
/
_1909.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.fishercoder.solutions;
public class _1909 {
public static class Solution1 {
/**
* credit: https://leetcode.com/problems/remove-one-element-to-make-the-array-strictly-increasing/discuss/1298827/Java-Short
*/
public boolean canBeIncreasing(int[] nums) {
boolean removed = false;
for (int i = 1; i < nums.length; i++) {
if (nums[i] <= nums[i - 1]) {
if (removed) {
return false;
} else {
removed = true;
}
if (i > 1 && nums[i] <= nums[i - 2]) {
nums[i] = nums[i - 1];
}
}
}
return true;
}
}
}