Python Dp Solution


  • 0
    class Solution(object):
        def checkPossibility(self, nums):
            nums = [-0xffffffff] + nums + [0xffffffff]
            recrd = [1] + [0 for i in range(len(nums) - 1)]
            flag = 1
            for i in range(1, len(nums)):
                if nums[i] >= nums[i - 1] and recrd[i - 1] == 1:
                    recrd[i] = 1
            for i in range(len(nums) - 2, 0, -1):
                if recrd[i - 1] == 1 and nums[i + 1] >= nums[i - 1] and flag == 1:
                    return True
                if nums[i] > nums[i + 1]:
                    flag = 0
            return recrd[-1] == 1
    

Log in to reply
 

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