classSolution: defcheckPossibility(self, nums: List[int]) -> bool: modified = False for i inrange(1, len(nums)): if nums[i] < nums[i - 1]: # Return False if modified before, or if these conditions are satisfied. if modified or ( # Ensure `i - 2` and `i + 1` exist, i > 1 and i < len(nums) - 1 # if `i - 2` > `i`, it's a YAB of YABY, and nums[i - 2] > nums[i] # if `i - 1` > `i + 1`, it's a ABY of YABY. and nums[i - 1] > nums[i + 1] ): returnFalse # If it's not the cases above, set modified to True, # no more chance for the next violation. modified = True returnTrue