We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f360496 + 9d71f60 commit 201fe76Copy full SHA for 201fe76
kotlin/0665-non-decreasing-array.kt
@@ -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