Skip to content

Commit fe425b4

Browse files
committed
Dec 3
1 parent d9d319a commit fe425b4

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def addSpaces(self, s: str, spaces: List[int]) -> str:
6+
res = ''
7+
ptr = 0
8+
for i in range(len(s)):
9+
if ptr < len(spaces) and i == spaces[ptr]:
10+
res += ' '
11+
ptr += 1
12+
res += s[i]
13+
return res
14+
15+
16+
def main():
17+
s = 'LeetcodeHelpsMeLearn'
18+
spaces = [8, 13, 15]
19+
assert Solution().addSpaces(s, spaces) == 'Leetcode Helps Me Learn'
20+
21+
s = 'icodeinpython'
22+
spaces = [1, 5, 7, 9]
23+
assert Solution().addSpaces(s, spaces) == 'i code in py thon'
24+
25+
s = 'spacing'
26+
spaces = [0, 1, 2, 3, 4, 5, 6]
27+
assert Solution().addSpaces(s, spaces) == ' s p a c i n g'
28+
29+
30+
if __name__ == '__main__':
31+
main()

2024-12-December-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
| --- | --- | --- | --- |
66
| December 1 | [1346. Check If N and Its Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist/) | Easy | Solved |
77
| December 2 | [1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | Solved |
8-
| December 3 | []() | | |
8+
| December 3 | [2109. Adding Spaces to a String](https://leetcode.com/problems/adding-spaces-to-a-string/) | Medium | Solved |
99
| December 4 | []() | | |
1010
| December 5 | []() | | |
1111
| December 6 | []() | | |
@@ -39,5 +39,5 @@
3939
| Level | Problems | Solved | Unsolved |
4040
| --- | --- | --- | --- |
4141
| Easy | 2 | 2 | 0 |
42-
| Medium | 0 | 0 | 0 |
42+
| Medium | 1 | 1 | 0 |
4343
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)