Programmers

[Programmers / Python 풀이] 문자열 나누기

Hoo_Dev 2022. 12. 22. 21:54
def solution(s):
    answer = 0
    word = s

    for i in range(len(word)):
        eq = 0
        oth = 0
        first_alpha = word[0]

        for j in range(len(word)):
            if eq != 0 and oth != 0 and eq == oth:
                word = word[j:]
                answer += 1
                break
            if first_alpha == word[j]:
                eq += 1
            elif first_alpha != word[j]:
                oth += 1
    answer += 1
    return answer