FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode-study/encode-and-decode-strings/daiyongg-kim.py at main · DaleStudy/leetcode-study · GitHub
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
359
Star
156
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
/
daiyongg-kim.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (34 loc) · 1 KB
Breadcrumbs
leetcode-study
/
encode-and-decode-strings
/
daiyongg-kim.py
Copy path
File metadata and controls
40 lines (34 loc) · 1 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
class
Solution
:
"""
@param: strs: a list of strings
@return: encodes a list of strings to a single string.
"""
def
encode
(
self
,
strs
):
# write your code here
result
=
""
for
word
in
strs
:
word_size
=
len
(
word
)
result
+=
str
(
word_size
)
+
"#"
+
word
return
result
# input ["lint","code","love","you"]
# output "4#lint4#code4#love3#you"
"""
@param: str: A string
@return: decodes a single string to a list of strings
"""
def
decode
(
self
,
str
):
# write your code here
result
=
[]
i
=
0
while
i
<
len
(
str
):
j
=
i
while
str
[
j
]
!=
"#"
:
#find the position of '#'
j
+=
1
my_number
=
int
(
str
[
i
:
j
])
start
=
j
+
1
# add 1 to skip '#'
end
=
j
+
1
+
my_number
result
.
append
(
str
[
start
:
end
])
i
=
end
return
result
# input "4#lint4#code4#love3#you"
# output ["lint","code","love","you"]
Back
|
FazBrowse Home
|
New Git URL