Skip to content

Commit 9a5a0f3

Browse files
authored
Merge pull request #2292 from a93a/main
Delete newer duplicate of Problem 665 in C++ and rename older contribution
2 parents 303ea5b + a375e41 commit 9a5a0f3

File tree

3 files changed

+18
-54
lines changed

3 files changed

+18
-54
lines changed

Diff for: cpp/0665-Non-Decreasing-Array.cpp

-18
This file was deleted.

Diff for: cpp/0665-non-decreasing-array.cpp

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
class Solution {
22
public:
33
bool checkPossibility(vector<int>& nums) {
4-
int count = 0;
5-
for(int i=1;i<nums.size();i++){
6-
if(nums[i-1]>nums[i]){
7-
count++;
8-
if(i>=2&&nums[i-2]>nums[i]){
9-
nums[i]=nums[i-1];
10-
}
11-
else{
12-
nums[i-1]=nums[i];
13-
}
4+
bool changed = false;
5+
6+
for(int i = 0; i < nums.size() - 1; i++){
7+
if(nums[i] <= nums[i+1]){
8+
continue;
149
}
10+
if(changed){
11+
return false;
12+
}
13+
14+
if(i == 0 || nums[i+1] >= nums[i-1]){
15+
nums[i] = nums[i+1];
16+
}
17+
else{
18+
nums[i+1] = nums[i];
19+
}
20+
changed = true;
1521
}
16-
return count<=1;
22+
23+
return true;
1724
}
1825
};

Diff for: cpp/665-Non-decreasing-Array.cpp

-25
This file was deleted.

0 commit comments

Comments
 (0)