We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 64324e3 commit c1738ebCopy full SHA for c1738eb
2109-adding-spaces-to-a-string.cpp
@@ -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