[LeetCode][Python3] 665. Non-decreasing Array
2018. 9. 13. 01:47 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/non-decreasing-array/description/
My Solution :
class Solution:
def checkPossibility(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
i = 0
j = len(nums)-1
while i < j:
if nums[i] > nums[i+1]:
break
i += 1
while i < j:
if nums[j] < nums[j-1]:
break
j -= 1
if j - i > 1:
return False
if 0 < i and j < len(nums)-1:
if nums[i-1] > nums[j] and nums[i] > nums[j+1]):
return False
return True
Comment :
진짜 어렵게 풀었다. 제출을 무려 9번이나 하고 통과했네 ㅠㅠ
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 3. Longest Substring Without Repeating Characters (0) | 2018.09.24 |
---|---|
[LeetCode][Python3] 2. Add Two Numbers (0) | 2018.09.24 |
[LeetCode][Python3] 53. Maximum Subarray (0) | 2018.09.21 |
[LeetCode][Python3] 38. Count and Say (0) | 2018.09.21 |
[LeetCode][Python3] 705. Design HashSet (0) | 2018.09.12 |
[LeetCode][Python3] 706. Design HashMap (0) | 2018.09.12 |
[LeetCode][Python3] 35. Search Insert Position (0) | 2018.09.12 |
[LeetCode][Python3] 28. Implement strStr() (0) | 2018.09.12 |
최근에 달린 댓글 최근에 달린 댓글