[프로그래머스] 문자열 나누기(python)

Effy_ee·2023년 10월 11일
0

코딩테스트

목록 보기
70/118

👾(Lv.01)문자열 나누기
https://school.programmers.co.kr/learn/courses/30/lessons/140108

🖥️ 답안

def solution(s):
    answer = 0
    i = 0

    while i < len(s):
        x = s[i] #새로운 알파벳이 기준
        count_x = 0
        count_not_x = 0
		#같은 문자열과 다른 문자열 횟수가 같아지만 안의 루프 탈출
        while i < len(s) and (count_x == 0 or count_x != count_not_x):
            if s[i] == x:
                count_x += 1
            else:
                count_not_x += 1
            
            i += 1
        
        answer += 1

    return answer

0개의 댓글