728x90
문자열 내 p와 y의 개수
문제 설명
.
문제 풀이
소스코드 : C++
#include <string>
#include <iostream>
using namespace std;
bool solution(string s){
int p=0,y=0;
for(char c : s){
c = tolower(c);
if(c=='p') p++;
if(c=='y') y++;
}
return p == y;
}
소스코드 : Python
def solution(s):
return s.count("p" or "P") == s.count("y" or "Y")
728x90
300x250