Skip to content

Commit

Permalink
Create divide-a-string-into-groups-of-size-k.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Jan 16, 2022
1 parent 4298ad9 commit df44086
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions C++/divide-a-string-into-groups-of-size-k.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Time: O(n)
// Space: O(1)

// string
class Solution {
public:
vector<string> divideString(string s, int k, char fill) {
vector<string> result((size(s) + (k - 1)) / k, string(k, fill));
for (int i = 0; i < size(s); ++i) {
result[i / k][i % k] = s[i];
}
return result;
}
};

0 comments on commit df44086

Please sign in to comment.