作者sustainer123 (caster )
看板Marginalman
標題Re: [閒聊] 每日leetcode
時間Mon Jul 1 10:07:10 2024
https://leetcode.com/problems/three-consecutive-odds
1550. Three Consecutive Odds
給定一個array
假設此數列有連續三個奇數 回傳True
反之回傳False
思路:
記數
Python Code:
class Solution:
def threeConsecutiveOdds(self, arr: List[int]) -> bool:
count = 0
for num in arr:
if num % 2 == 1:
count += 1
else:
count = 0
if count == 3:
return True
return False
我是ez守門員
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.194.160.111 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1719799634.A.701.html
推 oin1104: 大清早就在卷 我哭了 07/01 10:18
→ sustainer123: 早上刷題比較方便安排之後的時間 07/01 10:19
推 DJYOMIYAHINA: 別捲了 07/01 10:20