-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogrammers_120956.java
More file actions
53 lines (41 loc) · 1.19 KB
/
programmers_120956.java
File metadata and controls
53 lines (41 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.*;
class programmers_120956 {
public int solution(String[] babbling) {
int answer = 0;
String[] canSay = {"aya", "ye", "woo", "ma"};
for (String word : babbling) {
while (!word.isEmpty()) {
boolean matched = false;
for (String say : canSay) {
if (word.startsWith(say)) {
word = word.substring(say.length());
matched = true;
break;
}
}
if (!matched) {
break;
}
}
if (word.isEmpty()) {
answer++;
}
}
return answer;
}
/*
public int solution(String[] babbling) {
int answer = 0;
for(String str : babbling) {
for(String word : new String[] {"aya", "ye", "woo", "ma"}){
if(str.contains(word)){
str = str.replace(word, " ");
}
}
str = str.replace(" ", "");
if(str.equals("")) answer++;
}
return answer;
}
*/
}