先补昨天的
我不小心偷看到你板文章有人说到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