Skip to content

Commit 5420d07

Browse files
author
jinbeom
committed
Encode and Decode Strings Solution
1 parent 173cf0f commit 5420d07

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

encode-and-decode-strings/kayden.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution:
2+
3+
# 시간복잡도: O(N)
4+
# 공간복잡도: O(1)
5+
def encode(self, strs):
6+
res = ""
7+
for str in strs:
8+
size = len(str)
9+
res += str(size)
10+
res += str
11+
12+
return res
13+
14+
# 시간복잡도: O(N)
15+
# 공간복잡도: O(N)
16+
def decode(self, str):
17+
idx = 0
18+
limit = len(str)
19+
res = []
20+
21+
while idx < limit:
22+
num = str[idx]
23+
text = ""
24+
for _ in range(num):
25+
text += str[idx]
26+
idx+=1
27+
res.append(text)
28+
29+
return res

0 commit comments

Comments
 (0)