728x90
반응형
첫번째 코드
대소문자를 구분하지 않으므로 모두 소문자로 변경한 후에 알파벳을 비교한다.
전체 알파벳에 대하여 비교한 후, 개수가 일치한 경우 True, 아니면 False를 return 한다.
def solution(s):
count_p = 0
count_y = 0
s = s.lower()
for i in s:
if i == 'p':
count_p += 1
elif i == 'y':
count_y += 1
if count_p == count_y:
return True
else:
return False
통과!
링크
programmers/프로그래머스/1/12916. 문자열 내 p와 y의 개수 at main · ornni/programmers
repository for recording Programmers Algorithm problem solving - ornni/programmers
github.com
반응형