Re: [闲聊] 每日leetcode

楼主: DJYOMIYAHINA (通通打死)   2025-01-11 23:21:23
写了一堆像狗屎的判断是
跟小丑一样
我的智商就这样了
def canConstruct(self, s: str, k: int) -> bool:
cnt = [0 for _ in range(26)]
for c in s:
cnt[ord(c)-ord('a')] += 1
odd_cnt = [num%2==1 for num in cnt].count(True)
if odd_cnt>k:
return False
elif len(s)<k:
return False
elif (len(s)-odd_cnt)/2<(k-odd_cnt) and len(s)-k<0:
return False
return True
作者: sustainer123 (caster)   2025-01-11 23:22:00
你是大师
作者: Meaverzt (Meaverzt)   2025-01-11 23:25:00
大师
作者: oin1104 (是oin的说)   2025-01-11 23:37:00
你是大师

Links booklink

Contact Us: admin [ a t ] ucptt.com