Algorithm/Programmers

[Programmers - lv01] 문자열 내 p와 y의 개수 (cpp / python)

  • -
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
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.