mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 665.cpp
This commit is contained in:
parent
2a420466b6
commit
63e2720fe7
22
LeetCode-CN/665.cpp
Normal file
22
LeetCode-CN/665.cpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
class Solution {
|
||||
public:
|
||||
bool checkPossibility(vector<int>& nums) {
|
||||
int nrev = 0;
|
||||
|
||||
for(int i=1; i<nums.size(); i++) {
|
||||
if (nums[i-1] > nums[i]) {
|
||||
if (nrev) return false;
|
||||
nrev++;
|
||||
|
||||
if (i < 2) nums[i-1] = nums[i];
|
||||
else if (nums[i-2] <= nums[i]) {
|
||||
nums[i-1] = nums[i-2];
|
||||
} else {
|
||||
nums[i] = nums[i-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nrev < 2;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user