https://programmers.co.kr/learn/courses/30/lessons/12916?language=java 문자열 내 p와 y의 개수
- 문자열안 api를 통해서 문자 각각으로 p와 y로 비교를 할 수 있어야 한다.
import java.util.*;
public boolean solution(String s) {
boolean answer = true;
int pCount = 0;
int yCount = 0;
String[] strArray = s.split("");
for(String charItem : strArray){
if(charItem.toLowerCase().equals("p")){
pCount++;
}else if(charItem.toLowerCase().equals("y")){
yCount++;
}
}
if(pCount == yCount){
answer = true;
}else{
answer = false;
}
return answer;
}
이번 문제는 나 스스로 풀었다. 문자 하나하나를 비교하기 위해서 문자열 행렬로 변환 후에 하나씩 비교하는 방법을 이용했다.
https://velog.io/@godori/banner-maker-update GODORI
https://banner.godori.dev/ 배너생성기