Skip to content

Commit df44086

Browse files
authored
Create divide-a-string-into-groups-of-size-k.cpp
1 parent 4298ad9 commit df44086

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
// string
5+
class Solution {
6+
public:
7+
vector<string> divideString(string s, int k, char fill) {
8+
vector<string> result((size(s) + (k - 1)) / k, string(k, fill));
9+
for (int i = 0; i < size(s); ++i) {
10+
result[i / k][i % k] = s[i];
11+
}
12+
return result;
13+
}
14+
};

0 commit comments

Comments
 (0)