
charAt ์ ์ฌ์ฉํด์ p or P๋ฉด count ์ฆ๊ฐ, y or Y๋ฉด count ๊ฐ์์์ผ์
count๊ฐ 0์ด๋ฉด true, 0์ด ์๋๋ฉด false๋ฅผ ๋ฆฌํดํ๋ค.
class Solution {
boolean solution(String s) {
boolean answer = true;
int count=0;
for(int i=0; i<s.length(); i++){
if(s.charAt(i)=='p' || s.charAt(i)=='P'){
count++;
}else if(s.charAt(i)=='y' || s.charAt(i)=='Y'){
count--;
}
}
if(count!=0){
return false;
}else{
return answer;
}
}
}
'Algorithm > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [ํ๋ก๊ทธ๋๋จธ์ค/JAVA] ๊ฐ์ ์ซ์๋ ์ซ์ด (0) | 2021.11.13 |
|---|---|
| [ํ๋ก๊ทธ๋๋จธ์ค/JAVA] ๋ฌธ์์ด ๋ค๋ฃจ๊ธฐ ๊ธฐ๋ณธ (0) | 2021.11.06 |
| [ํ๋ก๊ทธ๋๋จธ์ค/JAVA] x๋งํผ ๊ฐ๊ฒฉ์ด ์๋ n๊ฐ์ ์ซ์ (0) | 2021.10.15 |
| [ํ๋ก๊ทธ๋๋จธ์ค/JAVA] ์๋ฐ์๋ฐ์๋ฐ์๋ฐ์๋ฐ์? (0) | 2021.10.13 |
| [ํ๋ก๊ทธ๋๋จธ์ค/JAVA] ๊ฐ์ด๋ฐ ๊ธ์ ๊ฐ์ ธ์ค๊ธฐ (0) | 2021.10.13 |