Re: [閒聊] 每日leetcode

看板Marginalman作者 (JerryChung)時間1月前 (2024/08/01 08:40), 編輯推噓1(104)
留言5則, 5人參與, 1月前最新討論串610/893 (看更多)
※ 引述《sustainer123 (caster )》之銘言: : https://leetcode.com/problems/number-of-senior-citizens : 2678. Number of Senior Citizens : 給你details 裡面有個人訊息 : 前十位數字是電話 : 第十一位字母是性別 : 第十二位到第十三位是年齡 : 回傳年齡>60的人數 : 思路: : 照題目敘述解題 : Python Code: : class Solution: : def countSeniors(self, details: List[str]) -> int: : result = 0 : for detail in details: : if int(detail[11:13]) > 60: : result += 1 : return result : 我是EZ守門員 Python Code: class Solution: def countSeniors(self, details: List[str]) -> int: return sum(1 for detail in details if int(detail[11:13]) > 60) 我只會寫這種題目了 用 len() 也可以 不過左右就要多 [] 不然 generator 沒有 len() -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.251.52.67 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1722472833.A.E71.html

08/01 08:40, 1月前 , 1F
才55p 吐了
08/01 08:40, 1F

08/01 08:40, 1月前 , 2F
四行==
08/01 08:40, 2F

08/01 08:42, 1月前 , 3F
四行倉庫
08/01 08:42, 3F

08/01 08:43, 1月前 , 4F
大師
08/01 08:43, 4F

08/01 20:01, 1月前 , 5F
大師
08/01 20:01, 5F
文章代碼(AID): #1cgjc1vn (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cgjc1vn (Marginalman)