Head vs breakz
[code] - 카카오 압축 python 본문
def solution(msg):
word_list =['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
status = True
total = True
count = 0
val_count = 0
answer = []
for i in range(len(msg)):
for j in range(len(msg),0,-1):
if msg[i:j] in word_list and status ==True :
answer.append(word_list.index(msg[i:j])+1)
word_list.append(msg[i:j+1])
count += j-i
if j-i > 1:
val_count = j-i-1
status = False
if count == len(msg):
total = False
break
elif status == False :
val_count -= 1
if val_count == 0:
status = True
break
if total == False:
break
return answer
2중 for문으로 i 와 j 의 방향을 반대로하여, 문자열을 좁히면서 실행되도록 하였다.
'Head > Code' 카테고리의 다른 글
[Code] - Python / lambda, map, reduce, filter 사용법 (0) | 2020.08.25 |
---|---|
[CODE] - ImageDataGenerator (0) | 2020.07.15 |
[code] - 카카오 튜플 python (0) | 2020.05.05 |
[code] - 카카오 n진수 게임 python (0) | 2020.05.04 |
[code] - 카카오 괄호변환 python (0) | 2020.05.04 |
Comments