File tree Expand file tree Collapse file tree 1 file changed +10
-19
lines changed Expand file tree Collapse file tree 1 file changed +10
-19
lines changed Original file line number Diff line number Diff line change 1
1
class Solution :
2
- """
3
- @param: strs: a list of strings
4
- @return: encodes a list of strings to a single string.
5
- """
6
-
7
2
def encode (self , strs ):
8
- res = ""
9
- for s in strs :
10
- res += str (len (s )) + "#" + s
11
- return res
12
-
13
- """
14
- @param: s: A string
15
- @return: decodes a single string to a list of strings
16
- """
3
+ return '' .join (map (lambda s : str (len (s )) + '#' + s , strs ))
17
4
18
5
def decode (self , s ):
19
- res , i = [], 0
20
-
6
+ res = []
7
+ i = 0
8
+
21
9
while i < len (s ):
22
10
j = i
23
- while s [j ] != "#" :
11
+ while s [j ] != '#' :
24
12
j += 1
25
13
length = int (s [i :j ])
26
- res .append (s [j + 1 : j + 1 + length ])
27
- i = j + 1 + length
14
+ i = j + 1
15
+ j = i + length
16
+ res .append (s [i :j ])
17
+ i = j
18
+
28
19
return res
You can’t perform that action at this time.
0 commit comments