File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
encode-and-decode-strings Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 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+ def encode (self , strs ):
8+ # write your code here
9+ result = ""
10+ for s in strs :
11+ result += str (len (s )) + "@" + s
12+ return result
13+
14+ """
15+ @param: str: A string
16+ @return: decodes a single string to a list of strings
17+ """
18+
19+ def decode (self , str ):
20+ # write your code here
21+ result = []
22+ i = 0
23+ while i < len (str ):
24+ j = i
25+ # ์์์ ์๋ ๊ฒฝ์ฐ
26+ while str [j ] != "@" :
27+ j += 1
28+ # ์์์ ์ธ ๊ฒฝ์ฐ
29+ length = int (str [i :j ])
30+ word = str [j + 1 : j + 1 + length ]
31+ result .append (word )
32+ i = j + 1 + length
33+ return result
You canโt perform that action at this time.
0 commit comments