์ฒด๊ฐ Level : โ
โ
โ
Review: ๋์ ํ ๋ฌธ์์ด ์๋ฅด๊ธฐ๋ก๋... ์ฝ๋์ง๊ธฐ๊ฐ ํ๋ค์ด์ replace ํํธ๋ฅผ ์ป๊ณ ์ฝ๊ฒ ํ ์ ์์๋ค!! |
๐ก "aya", "ye", "woo", "ma" ๋ค ๊ฐ์ง ๋ฐ์์ ์ต๋ ํ ๋ฒ์ฉ ์ฌ์ฉํด ์กฐํฉํ(์ด์ด ๋ถ์ธ) ๋ฐ์์ด ๋ช๊ฐ์ธ์ง ๋ฐํ.
1) ๋จผ์ ๋ฐฐ์ด์ ๋ด๊ธด ๊ฐ๊ฐ์ ๋ฐ์๋ค์ - ๋ก ๋ณํ์์ผ์ฃผ๊ณ
2) ์ ๊ทํํ์์ ํตํด์ - ๋ก๋ง ์ด๋ฃจ์ด์ง ๋ฐ์์ ์ฐพ์์ค๋ค.
3) ์นด์ดํ ํด์ฃผ๋ฉด ๋!
๐ฌmatches("^-+$") : - ๊ฐ ์์๋ถํฐ ๋๊น์ง ํ๊ฐ์ด์ ์กด์ฌํ๋ค๋ ๋ป (์ฆ - ๋ก๋ง ์ด๋ฃจ์ด์ง ๋ฌธ์์ด ์ฐพ๊ธฐ)
[์ฑ๊ณต]
import java.util.*;
class Solution {
public int solution(String[] babbling) {
int answer = 0;
String[] str = Arrays.copyOf(babbling,babbling.length);
for (int i =0 ; i < str.length; i++){
str[i] = str[i].replace("aya","---");
str[i] = str[i].replace("ye","--");
str[i] = str[i].replace("woo","---");
str[i] = str[i].replace("ma","--");
}
for (String s1 : str){
if (s1.matches("^-+$")){
answer++;
}
}
return answer;
}
}
[์คํจ]
class Solution {
public int solution(String[] babbling) {
int answer = 0;
String[] str = {"aya", "ye", "woo","ma"};
for (String s1 : babbling){
for (String s2 : str){
if (s1.contains(s2)){
if (s1.equals(s2)){
answer++;
}
}
}
}
Boolean flag = true;
for (String s1 : babbling){
for (int i =0 ; i<s1.length(); i++){
if (s1.substring(i).startsWith("aya")){
flag = true;
}else if (s1.substring(i).startsWith("woo")) {
flag = true;
}else if (s1.substring(i).startsWith("ya")) {
flag = true;
}else if (s1.substring(i).startsWith("ma")) {
flag = true;
}else {
flag = false;
}
}
if ( flag == true) {
answer ++;
}
}
return answer;
}
}