leetcode665 C++ 36ms 非递减数列 这题没啥意思

class Solution {
public:
    bool checkPossibility(vector<int>& nums) {

        if(nums.empty()){
            return false;
        }
        if(nums.size() == 1){
            return true;
        }
        int p = 0;
        int counter = 0;
        while(p<nums.size()-1){
            if(nums[p+1] < nums[p]){
                if(p == 0 || p+1 == nums.size() - 1){
                    counter++;
                }
                else{
                    if(nums[p-1] >= nums[p+1]){
                        nums[p+1] = nums[p];
                    }
                    else{
                        nums[p] = nums[p-1];
                    }
                    counter++;
                }
            }
            if(counter >= 2){
                return false;
            }
            p++;
        }
        return counter <=1;
    }
    
};
posted @ 2018-08-10 10:57  一条图图犬  阅读(415)  评论(0编辑  收藏  举报