Re: [閒聊] 每日leetcode

看板Marginalman作者 (通通打死)時間1年前 (2024/12/03 21:47), 編輯推噓0(001)
留言1則, 1人參與, 1年前最新討論串1176/1548 (看更多)
還蠻男的 不過有過就好 寫的好像也不是很好 def addSpaces(self, s: str, spaces: List[int]) -> str: ans = "" cur_i = 0 for i,c in enumerate(s): if cur_i<len(spaces) and i==spaces[cur_i]: ans = ans + f" {c}" cur_i += 1 else: ans = ans + c return ans 一開始寫這樣TLE 笑了 def addSpaces(self, s: str, spaces: List[int]) -> str: cur_cnt = 0 for num in spaces: s = s[:num+cur_cnt] + " " + s[num+cur_cnt:] cur_cnt += 1 return s -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1733233656.A.1BE.html

12/03 21:57, 1年前 , 1F
那樣會tleㄇ
12/03 21:57, 1F
文章代碼(AID): #1dJmlu6- (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dJmlu6- (Marginalman)