Deep_Dev
article thumbnail

 

 


for each๋ฌธ์œผ๋กœ ๋Œ๋ฉด์„œ p์™€ y์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ฐ๊ฐ count ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ’€์—ˆ๋Š”๋ฐ,

๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ์ฝ”๋“œ๋ฅผ ๋ณด๋‹ˆ ๋ณ€์ˆ˜ ํ•˜๋‚˜๋งŒ ์ด์šฉํ•ด์„œ ++, --์ด์šฉํ•ด์„œ count==0 ์ด๋ƒ๊ณ  ํ•˜๋Š”๊ฒƒ์ด ๋” ์ข‹์€ ์ฝ”๋“œ๊ฐ™์•˜๋‹ค.

( ํ›จ์”ฌ ๋” ์ข‹์€ ์ฝ”๋“œ๋Š” ์•„์ง ๋ฌด๋ฆฌ... )

 


 

class Solution {
    boolean solution(String s) {
   	   boolean answer=true;
       int p=0;
       int y=0;
       for(char x:s.toLowerCase().toCharArray()){
           if(x=='p')
               p++;
           else if(x=='y')
               y++;
       }
       if(p==y) return answer;
       else return false;
    }
}