내 답안
import java.util.*;
class Solution {
public List solution(String myStr) {
List<String> list = new ArrayList<String>();
String temp = "";
for(int i = 0 ; i < myStr.length(); i++){
char value = myStr.charAt(i);
if(value == 'a' || value == 'b' || value == 'c'){
if(temp != ""){
list.add(temp);
temp = "";
}
} else {
temp += value;
}
}
if(temp != ""){
list.add(temp);
temp = "";
}
if(list.size() == 0) list.add("EMPTY");
return list;
}
}
Java
복사
다른사람 풀이
import java.util.Arrays;
class Solution {
public String[] solution(String myStr) {
String[] arr = Arrays.stream(myStr.split("[abc]+")).filter(str -> !str.isEmpty()).toArray(String[]::new);
return arr.length == 0 ? new String[] { "EMPTY" } : arr;
}
}
Java
복사