File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
construct-binary-tree-from-preorder-and-inorder-traversal Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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
+ current_string = ""
24
+ i += 2
25
+ elif s [i : i + 2 ] == "//" :
26
+ current_string += "/"
27
+ i += 2
28
+ else :
29
+ current_string += s [i ]
30
+ i += 1
31
+
32
+ return decoded
You can’t perform that action at this time.
0 commit comments