File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
encode-and-decode-strings Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Constraints:
3+ 1. 0 <= strs.length <= 200
4+ 2. 0 <= strs[i].length <= 200
5+ 3. strs[i]๋ ์ ๋์ฝ๋ ๋ฌธ์๋ค๋ก๋ง ๊ตฌ์ฑ๋จ
6+ 4. encode๋ string์ ๋ฐ๋์ decode ๊ฐ๋ฅํด์ผ ํจ
7+
8+ Time Complexity: O(n)
9+
10+ Space Complexity: O(n)
11+
12+ ํ์ด๋ฐฉ๋ฒ:
13+ - encode: ๊ฐ ๋ฌธ์์ด ๋ค์ '#' ์ถ๊ฐํ์ฌ ํ๋๋ก ํฉ์นจ
14+ - decode: '#'์ ๊ธฐ์ค์ผ๋ก ๋ฌธ์์ด ๋ถํ
15+
16+ Further consideration:
17+ - ํ์ฌ ๋ฐฉ์์ ์
๋ ฅ ๋ฌธ์์ด์ '#'์ด ํฌํจ๋ ๊ฒฝ์ฐ ๋ฌธ์ ๋ฐ์ ๊ฐ๋ฅ
18+ - ๊ฐ์ ๋ฐฉ๋ฒ: ๋ฌธ์์ด ๊ธธ์ด + ๊ตฌ๋ถ์ + ๋ฌธ์์ด ํ์ ์ฌ์ฉ
19+ ์: ["Hello", "World"] -> "5#Hello5#World"
20+ """
21+
22+ class Solution :
23+ """
24+ @param: strs: a list of strings
25+ @return: encodes a list of strings to a single string.
26+ Examples:
27+ input: ["Hello", "World"]
28+ output: "Hello#World"
29+ """
30+ def encode (self , strs ):
31+ result = ""
32+ for s in strs :
33+ result = result + s + "#"
34+ return result [:- 1 ]
35+
36+ """
37+ @param: str: A string
38+ @return: decodes a single string to a list of strings
39+ Examples:
40+ input: "Hello#World"
41+ output: ["Hello", "World"]
42+ """
43+ def decode (self , str ):
44+ return str .split ("#" )
You canโt perform that action at this time.
0 commit comments