Skip to content

Commit 3abfd93

Browse files
committedAug 21, 2024
Refactor: Encode and Decode Strings
1 parent 6eed7ba commit 3abfd93

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed
 

‎encode-and-decode-strings/flynn.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ class Codec {
2727
// Decodes a single string to a list of strings.
2828
vector<string> decode(string s) {
2929
vector<string> res;
30-
int str_size = 0;
31-
string tmp = "";
3230

3331
auto it = s.begin();
3432
while (it != s.end()) {
35-
do {
33+
int str_size = 0;
34+
string tmp = "";
35+
36+
while (*it != '.') {
3637
str_size = str_size * 10 + (*it - '0');
3738
it++;
38-
} while (*it != '.');
39+
}
3940

4041
it++;
4142

@@ -45,8 +46,6 @@ class Codec {
4546
}
4647

4748
res.push_back(tmp);
48-
str_size = 0;
49-
tmp = "";
5049
}
5150

5251
return res;

0 commit comments

Comments
 (0)
Please sign in to comment.