Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2292 from a93a/main
Browse files Browse the repository at this point in the history
Delete newer duplicate of Problem 665 in C++ and rename older contribution
  • Loading branch information
a93a authored Mar 5, 2023
2 parents 303ea5b + a375e41 commit 9a5a0f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 54 deletions.
18 changes: 0 additions & 18 deletions cpp/0665-Non-Decreasing-Array.cpp

This file was deleted.

29 changes: 18 additions & 11 deletions cpp/0665-non-decreasing-array.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
class Solution {
public:
bool checkPossibility(vector<int>& nums) {
int count = 0;
for(int i=1;i<nums.size();i++){
if(nums[i-1]>nums[i]){
count++;
if(i>=2&&nums[i-2]>nums[i]){
nums[i]=nums[i-1];
}
else{
nums[i-1]=nums[i];
}
bool changed = false;

for(int i = 0; i < nums.size() - 1; i++){
if(nums[i] <= nums[i+1]){
continue;
}
if(changed){
return false;
}

if(i == 0 || nums[i+1] >= nums[i-1]){
nums[i] = nums[i+1];
}
else{
nums[i+1] = nums[i];
}
changed = true;
}
return count<=1;

return true;
}
};
25 changes: 0 additions & 25 deletions cpp/665-Non-decreasing-Array.cpp

This file was deleted.

0 comments on commit 9a5a0f3

Please sign in to comment.