Re: [閒聊] 每日leetcode
還蠻男的
不過有過就好
寫的好像也不是很好
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
12/03 21:57, 1F
討論串 (同標題文章)
完整討論串 (本文為第 1176 之 1548 篇):