Re: [閒聊] 每日leetcode

看板Marginalman作者 (通通打死)時間1年前 (2024/09/16 08:34), 1年前編輯推噓2(201)
留言3則, 3人參與, 1年前最新討論串864/1554 (看更多)
先補昨天的 我不小心偷看到你板文章有人說到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 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1726446880.A.99B.html ※ 編輯: DJYOMIYAHINA (125.229.37.69 臺灣), 09/16/2024 08:35:13

09/16 08:37, 1年前 , 1F
大師
09/16 08:37, 1F

09/16 08:41, 1年前 , 2F
靠北我才發現我的minute怎麼拚成這樣==
09/16 08:41, 2F

09/16 10:06, 1年前 , 3F
7
09/16 10:06, 3F
文章代碼(AID): #1cvtqWcR (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cvtqWcR (Marginalman)