還蠻男的 不過有過就好 寫的好像也不是很好 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 -- ※ 發信站: 批踢踢實業坊(pttsite.org.tw), 來自: 125.229.37.69 (臺灣) ※ 文章網址: https://pttsite.org.tw/Marginalman/M.1733233656.A.1BE