Re: [閒聊] 每日leetcode

作者: DJYOMIYAHINA (通通打死)   2024-09-16 08:34:38
先補昨天的
我不小心偷看到你板文章有人說到bitmask 才想得到==
自己想應該想不到
好南
def findTheLongestSubstring(self, s: str) -> int:
mp = {}
cur_bit = 0
mp[cur_bit] = -1
ans = 0
for i, c in enumerate(s):
# print(bin(cur_bit))
if c=='a' or c=='e' or c=='i' or c=='o' or c=='u':
cur_bit = cur_bit^(1 << (ord(c)-ord('a')))
if cur_bit in mp:
ans = max(ans, i-mp[cur_bit])
else:
mp[cur_bit] = i
return ans
然後今天的
直接無腦2d->1d
def findMinDifference(self, timePoints: List[str]) -> int:
mat = [0 for _ in range(24*60)]
for time in timePoints:
hour = int(time.split(':')[0])
mininute = int(time.split(':')[1])
mat[hour*60+mininute] += 1
pre, ans = -1, 10**9
mat = mat*2
for i, val in enumerate(mat):
if val > 1:
return 0
elif val == 1:
if pre != -1:
ans = min(ans, abs(i-pre))
pre = i
return ans
作者: PogChampLUL (火車站肥宅)   2024-09-16 08:37:00
大師
作者: DJYOMIYAHINA (通通打死)   2024-09-16 08:41:00
靠北我才發現我的minute怎麼拚成這樣==

Links booklink

Contact Us: admin [ a t ] ucptt.com