Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- dacon
- 더현대서울 맛집
- hackerrank
- Real or Not? NLP with Disaster Tweets
- 금융문자분석경진대회
- programmers
- AI 경진대회
- 코로나19
- Kaggle
- 데이콘
- SW Expert Academy
- 우분투
- 프로그래머스 파이썬
- ubuntu
- 맥북
- gs25
- PYTHON
- 편스토랑 우승상품
- github
- Docker
- leetcode
- 백준
- 프로그래머스
- 편스토랑
- 캐치카페
- ChatGPT
- 파이썬
- Git
- 자연어처리
- Baekjoon
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 896. Monotonic Array (Python) 본문
728x90
반응형
An array is monotonic if it is either monotone increasing or monotone decreasing.
An array A is monotone increasing if for all i <= j, A[i] <= A[j]. An array A is monotone decreasing if for all i <= j, A[i] >= A[j].
Return true if and only if the given array A is monotonic.
Example 1:
Input: [1,2,2,3]
Output: true
Example 2:
Input: [6,5,4,4]
Output: true
Example 3:
Input: [1,3,2]
Output: false
Example 4:
Input: [1,2,4,5]
Output: true
Example 5:
Input: [1,1,1]
Output: true
Note:
- 1 <= A.length <= 50000
- -100000 <= A[i] <= 100000
Solution
class Solution:
def isMonotonic(self, A: List[int]) -> bool:
reverse_flag = False
if max(A) == A[0]:
reverse_flag = True
sorted_A = sorted(A, reverse=reverse_flag)
if sorted_A == A:
return True
return False
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 504. Base 7 (Python) (0) | 2020.10.12 |
---|---|
[leetCode] 1470. Shuffle the Array (Python) (0) | 2020.10.10 |
[leetCode] 258. Add Digits (Python) (0) | 2020.10.08 |
[leetCode] 1089. Duplicate Zeros (Python) (0) | 2020.10.07 |
[leetCode] 17. Letter Combinations of a Phone Number (Python) (0) | 2020.10.06 |
Comments