삽집하는 개발들/알고리즘

[17일차][프로그래머스][140108]문자열 나누기

악투 2023. 7. 4. 19:10
반응형
def solution(s):
    same_count = 0
    other_count = 0
    check_char = ""
    result = 0
    
    for char in s:        
        if len(check_char) == 0:
            check_char = char
            same_count += 1
        else:
            if check_char == char:
                same_count += 1
            else:
                other_count += 1
                
            if same_count == other_count:
                result += 1
                check_char = ""
            else:
                pass
    
    result = result+1 if len(check_char) != 0 else result
                
    return result
반응형