Re: [閒聊] 每日leetcode
看板Marginalman作者JerryChungYC (JerryChung)時間1月前 (2024/08/01 08:40)推噓1(1推 0噓 4→)留言5則, 5人參與討論串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
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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 610 之 893 篇):