Skip to content

Commit

Permalink
Create 0665-Non-Decreasing-Array.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankush11903 authored Jan 12, 2023
1 parent 6b15c8f commit 547f745
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cpp/0665-Non-Decreasing-Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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];
}
}
}
return count<=1;
}
};

0 comments on commit 547f745

Please sign in to comment.