Skip to content

Commit 201fe76

Browse files
authored
Merge pull request #2169 from a93a/main
Create 0665-non-decreasing-array.kt
2 parents f360496 + 9d71f60 commit 201fe76

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

kotlin/0665-non-decreasing-array.kt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
fun checkPossibility(nums: IntArray): Boolean {
3+
var modified = false
4+
for(i in 0 until nums.size-1){
5+
if(nums[i+1] < nums[i]) {
6+
if(modified) return false
7+
if(i == 0 || nums[i+1] >= nums[i-1]) nums[i] = nums[i+1]
8+
else nums[i+1] = nums[i]
9+
modified = true
10+
}
11+
}
12+
return true
13+
}
14+
}

0 commit comments

Comments
 (0)