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 635fcd7 commit 427ed1cCopy full SHA for 427ed1c
1 file changed
encode-and-decode-strings/hyeri0903.py
@@ -0,0 +1,24 @@
1
+class Solution:
2
+ """
3
+ @param: strs: a list of strings
4
+ @return: encodes a list of strings to a single string.
5
6
+ def encode(self, strs: List[str]):
7
+ text = ""
8
+ for str in strs:
9
+ text += f"{len(str)}:{str}"
10
+ return text
11
+
12
13
+ @param: str: A string
14
+ @return: decodes a single string to a list of strings
15
16
+ def decode(self, s: str):
17
+ output = []
18
+ start = 0
19
+ while start < len(s):
20
+ mid = s.find(":", start)
21
+ length = int(s[start:mid])
22
+ output.append(s[mid + 1 : mid + 1 + length])
23
+ start = mid + 1 + length
24
+ return output
0 commit comments