본문 바로가기
python-algorithm

leetcode 1702B - Polycarp Writes a String from Memory

by 무적김두칠 2022. 7. 19.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def sol(s):
    cnt=0
    days=1
    string_list = []
    for i in s:
        if i in string_list:
            pass
        else :
            if cnt>=3:
                cnt=0
                days+=1
                string_list = []
            string_list.append(i)
            cnt+=1
    return days
for i in range(int(input())):
    print(sol(input()))
cs
반응형

댓글