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 28d2fcc commit 57a55c3Copy full SHA for 57a55c3
encode-and-decode-strings/dylan-jung.cpp
@@ -0,0 +1,25 @@
1
+class Codec {
2
+ public:
3
+ string encode(vector<string>& strs) {
4
+ string result;
5
+ for (const string& s : strs) {
6
+ result += to_string(s.size()) + "#" + s;
7
+ }
8
+ return result;
9
10
+
11
+ vector<string> decode(string s) {
12
+ vector<string> result;
13
+ int i = 0;
14
+ while (i < s.size()) {
15
+ int j = i;
16
+ while (s[j] != '#') j++;
17
+ int length = stoi(s.substr(i, j - i));
18
+ string cur = s.substr(j + 1, length);
19
+ result.push_back(cur);
20
+ i = j + 1 + length;
21
22
23
24
+ };
25
0 commit comments