GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/python/665_Non-decreasing_Array.py at master · qiyuangong/leetcode Expand file tree/ Copy path665_Non-decreasing_Array.pyMore file actions 38 lines (37 loc) · 1.32 KB / Copy path665_Non-decreasing_Array.pyFile metadata and controls38 lines (37 loc) · 1.32 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 class Solution(object): # def checkPossibility(self, nums): # """ # :type nums: List[int] # :rtype: bool # """ # pos = None # # Check if there are more than 2 broken point # # record first index # for i in range(len(nums) - 1): # if nums[i] > nums[i + 1]: # if pos is not None: # return False # pos = i # if pos is None or pos == 0 or pos == len(nums) - 2: # return True # # Remove pos or remove pos + 1 # return (nums[pos - 1] <= nums[pos + 1] or nums[pos] <= nums[pos + 2]) def checkPossibility(self, nums): """ :type nums: List[int] :rtype: bool """ # https://leetcode.com/problems/non-decreasing-array/discuss/106826/JavaC%2B%2B-Simple-greedy-like-solution-with-explanation broken_num = 0 for i in range(len(nums) - 1): if (nums[i] > nums[i + 1]): broken_num += 1 if broken_num >= 2: return False if (i - 1 < 0 or nums[i - 1] <= nums[i + 1]): # Remove i nums[i] = nums[i + 1] else: # Remove i + 1 nums[i + 1] = nums[i] return True |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |