내 답안
import java.util.*;
class Solution {
public String[] solution(String myString) {
String[] strArr = myString.split("x");
ArrayList<String> list = new ArrayList<>();
for(String str : strArr){
if(!str.isEmpty()){
list.add(str);
}
}
String[] result = new String[list.size()];
list.toArray(result);
Arrays.sort(result);
return result;
}
}
Java
복사
다른사람 풀이
import java.util.*;
class Solution {
public String[] solution(String myString) {
StringTokenizer st = new StringTokenizer(myString, "x");
int idx = 0, N = st.countTokens();
String[] result = new String[N];
for (int n = 0;n < N;n++)
result[idx++] = st.nextToken();
Arrays.sort(result);
return result;
}
}
Java
복사