encode-and-decode-string 1.0.0
Encode and Decode String
Loading...
Searching...
No Matches
Solution Class Reference

Public Member Functions

string encode (vector< string > &strs)
 
vector< string > decode (string &str)
 

Detailed Description

Definition at line 5 of file main.cpp.

Member Function Documentation

◆ decode()

vector< string > Solution::decode ( string &  str)
inline

Definition at line 24 of file main.cpp.

25 {
26 if (str.empty())
27 return {};
28 list<string> decoded_list;
29 int start_index = 0;
30 for (int i = 0; i < (int)str.length(); ++i)
31 {
32 if (str[i] == ';' && i >= 1 && str[i - 1] == ':')
33 {
34 decoded_list.push_back(str.substr(start_index, ((i - 1) - start_index)));
35 start_index = i + 1;
36 }
37 }
38 if (decoded_list.empty())
39 return {str};
40 return vector<string>(decoded_list.begin(), decoded_list.end());
41 }

Referenced by main().

◆ encode()

string Solution::encode ( vector< string > &  strs)
inline

Definition at line 12 of file main.cpp.

13 {
14 string encoded("");
15 for (const string& el: strs)
16 encoded += el + ":;";
17 return encoded;
18 }

Referenced by main().


The documentation for this class was generated from the following file: