프로그래밍
프로그래머스 문자열 내의 p와 y의 개수(JAVA, toLowerCase().split(""), equals)
노마드선샤인
2023. 2. 11. 13:34
728x90
class Solution {
boolean solution(String s) {
int pCount = 0, yCount = 0;
String[] array = s.toLowerCase().split(""); //소문자로 바꾸고 잘라 배열에 넣음
for (int i = 0; i < array.length; i++)
{
if ("p".equals(array[i]))
{
pCount++;
}
else if ("y".equals(array[i]))
{
yCount++;
}
}
if (pCount != yCount)
{
return false;
}
return true;
}
}
728x90