https://leetcode.com/problems/adding-spaces-to-a-string/
class Solution:
def addSpaces(self, s: str, spaces: List[int]) -> str:
ans=s[:spaces[0]]
for i in range(1,len(spaces)):
ans+=" "+s[spaces[i-1]:spaces[i]];
ans+=" "+s[spaces[len(spaces)-1]::]
return ans;
시간이나 메모리나 효율이 그닥인 방법이라... 좀 더 효율적으로 써야 할 듯
'Algorithm > Python' 카테고리의 다른 글
프로그래머스 - 다음 큰 숫자 (0) | 2022.09.22 |
---|---|
프로그래머스 - 프린터 (0) | 2022.09.22 |
프로그래머스- 두 큐 합 같게 만들기 (1) | 2022.08.26 |
Binary Search - 백준#1300 K번째 수 (0) | 2022.08.18 |
BFS - 백준 #7576 토마토 (0) | 2022.08.17 |