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 847e510 commit d6819caCopy full SHA for d6819ca
encode-and-decode-strings/mangodm-web.py
@@ -0,0 +1,32 @@
1
+from typing import List
2
+
3
4
+class Codec:
5
+ def encode(self, strs: List[str]) -> str:
6
+ """Encodes a list of strings to a single string."""
7
+ encoded = []
8
9
+ for s in strs:
10
+ encoded.append(s.replace("/", "//") + "/:")
11
12
+ return "".join(encoded)
13
14
+ def decode(self, s: str) -> List[str]:
15
+ """Decodes a single string to a list of strings."""
16
+ decoded = []
17
+ current_string = ""
18
+ i = 0
19
20
+ while i < len(s):
21
+ if s[i : i + 2] == "/:":
22
+ decoded.append(current_string)
23
24
+ i += 2
25
+ elif s[i : i + 2] == "//":
26
+ current_string += "/"
27
28
+ else:
29
+ current_string += s[i]
30
+ i += 1
31
32
+ return decoded
0 commit comments