Concise and Straightforward C++ Solution


  • 0
    D
    bool checkPossibility(vector<int>& nums) {
            if (nums.size() <= 2) return true;
            bool flag = true;
            for (int i = 1; i < nums.size(); i++)
                if (nums[i] < nums[i - 1]){
                    if (!flag) return false;
                    if (i > 1 && nums[i] < nums[i - 2])
                        nums[i] = nums[i - 1];
                    f = false;
                }
            return true;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.