Skip to content

Commit

Permalink
Encode and Decode Strings Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
jinbeom committed Aug 24, 2024
1 parent 173cf0f commit 5420d07
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions encode-and-decode-strings/kayden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Solution:

# 시간복잡도: O(N)
# 공간복잡도: O(1)
def encode(self, strs):
res = ""
for str in strs:
size = len(str)
res += str(size)
res += str

return res

# 시간복잡도: O(N)
# 공간복잡도: O(N)
def decode(self, str):
idx = 0
limit = len(str)
res = []

while idx < limit:
num = str[idx]
text = ""
for _ in range(num):
text += str[idx]
idx+=1
res.append(text)

return res

0 comments on commit 5420d07

Please sign in to comment.