FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode-study/encode-and-decode-strings/PDKhan.cpp at main · DaleStudy/leetcode-study · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
DaleStudy
/
leetcode-study
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
361
Star
154
Code
Issues
75
Pull requests
2
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode-study
/
encode-and-decode-strings
/
PDKhan.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
43 lines (34 loc) · 1.05 KB
Breadcrumbs
leetcode-study
/
encode-and-decode-strings
/
PDKhan.cpp
Copy path
File metadata and controls
43 lines (34 loc) · 1.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class
Solution
{
public:
/*
* @param strs: a list of strings
* @return: encodes a list of strings to a single string.
*/
string
encode
(vector<string> &strs) {
//
write your code here
string code;
for
(
const
string& s : strs){
code +=
to_string
(s.
size
()) +
"
:
"
+ s;
}
return
code;
}
/*
* @param str: A string
* @return: decodes a single string to a list of strings
*/
vector<string>
decode
(string &str) {
//
write your code here
vector<string> result;
int
i;
while
(i < str.
size
()){
int
j = i;
while
(str[j] !=
'
:
'
)
j++;
int
len =
stoi
(str.
substr
(i, j - i);
string word = str.
substr
(j +
1
, len);
result.
push_back
(word);
i = j +
1
+ len;
}
return
result;
}
};
Back
|
FazBrowse Home
|
New Git URL