Simple Acc Solution


  • 0
            public bool CheckPossibility(int[] nums)
            {
                if (nums.Length == 0 || nums == null) return false;
                if (nums.Length == 1) return true;
    
                bool changed = false;
    
                for (int i = 0; i < nums.Length-1; i++)
                {
                    if(nums[i]>nums[i+1])
                    {
                        if (changed) return false;
                        changed = true;
    
                        if (i >0 && nums[i + 1] < nums[i - 1])
                            nums[i + 1] = nums[i];
                        else nums[i] = nums[i+1];
                    }
                }
                return true;
            }
    

Log in to reply
 

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