Skip to content

Commit c1738eb

Browse files
committed
added 2109 - daily for december 3, 2024
1 parent 64324e3 commit c1738eb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

2109-adding-spaces-to-a-string.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
2109. Adding Spaces to a String
3+
4+
Leetcode Daily Question for December 3, 2024
5+
6+
Runtime: 17 ms (beats 73.49%)
7+
Memory: 82.34 MB (beats 88.45%)
8+
*/
9+
10+
class Solution {
11+
public:
12+
string addSpaces(string s, vector<int>& spaces) {
13+
string res;
14+
res.reserve(s.size() + spaces.size());
15+
auto spi = spaces.begin();
16+
int i = 0;
17+
for (; i < s.size() && spi != spaces.end(); ++i) {
18+
if (i == *spi) {
19+
res.push_back(' ');
20+
spi++;
21+
}
22+
res.push_back(s[i]);
23+
}
24+
res.append(s.begin() + i, s.end());
25+
return res;
26+
}
27+
};

0 commit comments

Comments
 (0)