题解的做法都太复杂了,我的可能好理解一些
class Solution { public: bool canBeIncreasing(vector<int>& nums) { int size = nums.size(); if(size == 2) return true; bool isDown = false;//isDown表示是否出现过一次nums[i-1] >= nums[i]的下降 if(nums[0] >= nums[1]) isDown = true; //考虑几种特殊情况,比如8 9 1 2; 1 2 0 3 4; 1 2 9 3 4 for(int i = 2;i < size-1;i++){ if(nums[i-1] >= nums[i]){ if(isDown == true) return false;//如果出现了两次下降,说明删除一个元素无法保证严格单增 if(nums[i-2] >= nums[i] && nums[i-1] >= nums[i+1]) return false;//前面防类似8 9 1 2,后面防1 2 0 3 4 isDown = true; } } if(nums[size-2] >= nums[size-1] && isDown == true) return false; return true; } };
标签:return,nums,递增,1909,false,isDown,true,leetcode,size From: https://www.cnblogs.com/uacs2024/p/18578227