This commit is contained in:
parent
633fef64b3
commit
635a34eb91
1 changed files with 14 additions and 0 deletions
14
medium/adding_spaces_to_a_string.py
Normal file
14
medium/adding_spaces_to_a_string.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# https://leetcode.com/problems/adding-spaces-to-a-string
|
||||
from typing import List
|
||||
|
||||
class Solution:
|
||||
def addSpaces(self, s: str, spaces: List[int]) -> str:
|
||||
result = []
|
||||
last_index = 0
|
||||
for index in spaces:
|
||||
result.append(s[last_index:index])
|
||||
result.append(" ")
|
||||
last_index = index
|
||||
result.append(s[last_index:len(s)])
|
||||
return "".join(result)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue