forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmangodm-web.py
More file actions
32 lines (25 loc) · 820 Bytes
/
mangodm-web.py
File metadata and controls
32 lines (25 loc) · 820 Bytes
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
from typing import List
class Codec:
def encode(self, strs: List[str]) -> str:
"""Encodes a list of strings to a single string."""
encoded = []
for s in strs:
encoded.append(s.replace("/", "//") + "/:")
return "".join(encoded)
def decode(self, s: str) -> List[str]:
"""Decodes a single string to a list of strings."""
decoded = []
current_string = ""
i = 0
while i < len(s):
if s[i : i + 2] == "/:":
decoded.append(current_string)
current_string = ""
i += 2
elif s[i : i + 2] == "//":
current_string += "/"
i += 2
else:
current_string += s[i]
i += 1
return decoded