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
- Git
- 캐치카페
- 프로그래머스 파이썬
- 맥북
- programmers
- dacon
- ChatGPT
- PYTHON
- ubuntu
- 우분투
- 편스토랑
- 데이콘
- 자연어처리
- Kaggle
- leetcode
- gs25
- hackerrank
- github
- Docker
- AI 경진대회
- 금융문자분석경진대회
- 코로나19
- 파이썬
- SW Expert Academy
- 편스토랑 우승상품
- Baekjoon
- 백준
- 더현대서울 맛집
- 프로그래머스
- Real or Not? NLP with Disaster Tweets
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1550. Three Consecutive Odds (Python) 본문
728x90
반응형
Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false.
Example 1:
Input: arr = [2,6,4,1]
Output: false
Explanation: There are no three consecutive odds.
Example 2:
Input: arr = [1,2,34,3,4,5,7,23,12]
Output: true
Explanation: [5,7,23] are three consecutive odds.
Constraints:
- 1 <= arr.length <= 1000
- 1 <= arr[i] <= 1000
Solution
class Solution:
def threeConsecutiveOdds(self, arr: List[int]) -> bool:
cnt = 0
for num in arr:
if num % 2 == 1:
cnt = cnt + 1
if cnt == 3:
return True
else:
cnt = 0
return False
Solution
class Solution:
def threeConsecutiveOdds(self, arr: List[int]) -> bool:
if len(arr) < 3:
return False
for i in range(len(arr)-2):
if (arr[i] % 2 == 1) and (arr[i+1] % 2 == 1) and (arr[i+2] % 2 == 1):
return True
return False
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 705. Design HashSet (Python) (0) | 2020.09.17 |
---|---|
[leetCode] 1356. Sort Integers by The Number of 1 Bits (Python) (0) | 2020.09.16 |
[leetCode] 1365. How Many Numbers Are Smaller Than the Current Number (Python) (2) | 2020.09.14 |
[leetCode] 500. Keyboard Row (Python) (0) | 2020.09.13 |
[leetCode] 811. Subdomain Visit Count (Python) (0) | 2020.09.12 |
Comments