forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKwonNayeon.py
More file actions
44 lines (38 loc) ยท 1.14 KB
/
KwonNayeon.py
File metadata and controls
44 lines (38 loc) ยท 1.14 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
"""
Constraints:
1. 0 <= strs.length <= 200
2. 0 <= strs[i].length <= 200
3. strs[i]๋ ์ ๋์ฝ๋ ๋ฌธ์๋ค๋ก๋ง ๊ตฌ์ฑ๋จ
4. encode๋ string์ ๋ฐ๋์ decode ๊ฐ๋ฅํด์ผ ํจ
Time Complexity: O(n)
Space Complexity: O(n)
ํ์ด๋ฐฉ๋ฒ:
- encode: ๊ฐ ๋ฌธ์์ด ๋ค์ '#' ์ถ๊ฐํ์ฌ ํ๋๋ก ํฉ์นจ
- decode: '#'์ ๊ธฐ์ค์ผ๋ก ๋ฌธ์์ด ๋ถํ
Further consideration:
- ํ์ฌ ๋ฐฉ์์ ์
๋ ฅ ๋ฌธ์์ด์ '#'์ด ํฌํจ๋ ๊ฒฝ์ฐ ๋ฌธ์ ๋ฐ์ ๊ฐ๋ฅ
- ๊ฐ์ ๋ฐฉ๋ฒ: ๋ฌธ์์ด ๊ธธ์ด + ๊ตฌ๋ถ์ + ๋ฌธ์์ด ํ์ ์ฌ์ฉ
์: ["Hello", "World"] -> "5#Hello5#World"
"""
class Solution:
"""
@param: strs: a list of strings
@return: encodes a list of strings to a single string.
Examples:
input: ["Hello", "World"]
output: "Hello#World"
"""
def encode(self, strs):
result = ""
for s in strs:
result = result + s + "#"
return result[:-1]
"""
@param: str: A string
@return: decodes a single string to a list of strings
Examples:
input: "Hello#World"
output: ["Hello", "World"]
"""
def decode(self, str):
return str.split("#")