Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- Singleton Pattern
- KAKAO
- k8s
- cpu scheduling
- golang
- GCP
- Top-down
- kubernetes
- GKE
- 피보나치
- 파이썬
- github
- Kotlin
- 그리디
- Programmers
- Dynamic Programming
- docker
- go
- Observer Pattern
- Python
- mobaXTerm
- 알고리즘
- easy
- 백준
- Backjoon
- java
- BubbleSort
- Codility
- LeetCode
Archives
- Today
- Total
To Be Developer
[LeetCode] Monotonic Array (Python) 본문
https://leetcode.com/problems/monotonic-array/
class Solution(object):
def isMonotonic(self, A):
"""
:type A: List[int]
:rtype: bool
"""
# A의 길이
ln = len(A)
# A의 길이가 1이면 무조건 True
if ln == 1:
return True
# Decrease면 False, increase 면 True
inDe = None
# 1~ln-1 까지 반복
for i in range(1, ln):
# 처음 inDe 가 비어있는 것은 A[i-1] 과 A[i]는 같다는 것을 뜻함
if inDe == None and A[i-1] != A[i]:
# Decrease
if A[i-1] > A[i]:
inDe = True
# increase
else:
inDe = False
pass
# Decrease 일 경우
if inDe:
if A[i-1] >= A[i]:
pass
else:
return False
# increase 일 경우
else:
if A[i-1] <= A[i]:
pass
else:
return False
# 무사히 통과하였을 경우 True 리턴
return True
if __name__ == "__main__":
inputData = []
sl = Solution().isMonotonic(inputData)
'알고리즘 > LeetCode' 카테고리의 다른 글
| [LeetCode] 965. Univalued Binary Tree (Python) (0) | 2019.04.08 |
|---|---|
| [LeetCode] 509. Fibonacci Number (GoLang, Python) (0) | 2019.04.07 |
| [LeetCode] Find the Difference (Python) (0) | 2019.04.03 |
| [LeetCode] 643. Maximum Average SubArray I (GoLang, Python) (0) | 2019.04.02 |
| [LeetCode] 724. Find Pivot Index (GoLang, Python) (0) | 2019.04.01 |