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 |
Tags
- gs25
- Docker
- Real or Not? NLP with Disaster Tweets
- hackerrank
- ubuntu
- 자연어처리
- Kaggle
- 우분투
- 금융문자분석경진대회
- 편스토랑 우승상품
- ChatGPT
- leetcode
- 편스토랑
- Baekjoon
- dacon
- SW Expert Academy
- 백준
- programmers
- 프로그래머스
- 더현대서울 맛집
- 데이콘
- Git
- 캐치카페
- 파이썬
- 프로그래머스 파이썬
- AI 경진대회
- 맥북
- 코로나19
- github
- PYTHON
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



SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'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