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
- 편스토랑
- github
- 우분투
- Docker
- 프로그래머스
- Git
- Kaggle
- dacon
- ubuntu
- Real or Not? NLP with Disaster Tweets
- PYTHON
- ChatGPT
- 코로나19
- Baekjoon
- 자연어처리
- 파이썬
- 백준
- gs25
- 편스토랑 우승상품
- 맥북
- leetcode
- 캐치카페
- 데이콘
- hackerrank
- AI 경진대회
- 프로그래머스 파이썬
- 더현대서울 맛집
- programmers
- SW Expert Academy
- 금융문자분석경진대회
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 941. Valid Mountain Array (Python) 본문
728x90
반응형
Given an array of integers arr, return true if and only if it is a valid mountain array.
Recall that arr is a mountain array if and only if:
- arr.length >= 3
- There exists some i with 0 < i < arr.length - 1 such that:
- arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
- arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
Example 1:
Input: arr = [2,1]
Output: false
Example 2:
Input: arr = [3,5,5]
Output: false
Example 3:
Input: arr = [0,3,2,1]
Output: true
Constraints:
- 1 <= arr.length <= 104
- 0 <= arr[i] <= 104
Solution
class Solution:
def validMountainArray(self, A: List[int]) -> bool:
incre_flag = True
answer = True
if len(A) < 3:
answer = False
else:
for i in range(len(A)-1):
if A[i] == A[i+1]:
answer = False
break
elif A[i] > A[i+1]:
if i == 0:
answer = False
break
else:
incre_flag = False
elif incre_flag == False and A[i] < A[i+1]:
answer = False
break
elif i == len(A) - 2 and incre_flag:
answer = False
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 1009. Complement of Base 10 Integer (Python) (0) | 2021.01.31 |
---|---|
[leetCode] 328. Odd Even Linked List (Python) (0) | 2021.01.30 |
[leetCode] 1486. XOR Operation in an Array (Python) (0) | 2021.01.28 |
[leetCode] 476. Number Complement (Python) (0) | 2021.01.27 |
[leetCode] 784. Letter Case Permutation (Python) (0) | 2021.01.26 |
Comments