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 6328dc6 commit 905eb33Copy full SHA for 905eb33
1 file changed
encode-and-decode-strings/parkhojeong.py
@@ -0,0 +1,28 @@
1
+class Codec:
2
+ def encode(self, strs: List[str]) -> str:
3
+ """Encodes a list of strings to a single string.
4
+ """
5
+ encoded = ""
6
+ for s in strs:
7
+ encoded += f"{len(s):03d}{s}"
8
+ return encoded
9
+
10
+ def decode(self, s: str) -> List[str]:
11
+ """Decodes a single string to a list of strings.
12
13
14
+ decoded = []
15
+ i = 0
16
+ while i < len(s):
17
+ s_start_idx = i + 3
18
+ s_len = int(s[i:s_start_idx])
19
+ decoded.append(s[s_start_idx:s_start_idx + s_len])
20
21
+ i = s_start_idx + s_len
22
23
+ return decoded
24
25
26
+# Your Codec object will be instantiated and called as such:
27
+# codec = Codec()
28
+# codec.decode(codec.encode(strs))
0 commit comments