프로그래머스/Lv. 1

19. 문자열 내 p와 y의 개수

Seohyeong Lee 2024. 7. 12. 18:09

유형 : 구현

풀이 시간 : 3분 

def solution(s):
    answer = True
    slist = list(s.lower())
    pcount = 0
    ycount = 0
    for ch in slist:
        if ch == 'p':
            pcount += 1
        elif ch == 'y':
            ycount += 1
    if pcount != ycount:
        answer = False
    return answer