class Solution:
def encode(self, strs: List[str]) -> str:
res = ""
if strs:
res += strs[0]
for s in strs[1:]:
res += "#" + s
return res
def decode(self, s: str) -> List[str]:
res = []
res = s.split('#') # '#'을 기준으로 문자열을 나눔
return res
-->Run으로 돌아가긴하는데, wrong answer 뜸
class Solution:
def encode(self, strs: List[str]) -> str:
res = ""
for s in strs:
res += str(len(s))+"#" + s
return res
def decode(self, s: str) -> List[str]:
res = []
i=0
while i<len(s):
j=i
while s[j] != '#': # s[j]가 '#'이 아닐때까지 반복
j+= 1
length = int(s[i:j]) #첫번째 루프에서 length는 s[0:1] == 첫번째로 쓴 str(len(s)) 이 값..
i = j + 1
j = i + length
res.append(s[i:j]) #이 때 추가됨.
i=j
return res