내 답안
import java.util.ArrayList;
import java.util.List;
class Solution {
public String[] solution(String[] todo_list, boolean[] finished) {
List<String> list = new ArrayList<>();
for (int i = 0; i < todo_list.length; i++) {
if (!finished[i]) {
list.add(todo_list[i]);
}
}
return list.toArray(list.toArray(new String[0]));
}
}
Java
복사
다른 사람 풀이
class Solution {
public String[] solution(String[] todo_list, boolean[] finished) {
String str = "";
for(int i=0; i<finished.length; i++){
str = finished[i]==false ? str+todo_list[i]+"," : str;
}
return str.split(",");
}
}
Java
복사
import java.util.*;
class Solution {
public String[] solution(String[] todo_list, boolean[] finished) {
ArrayList <String> al = new ArrayList <> ();
for(int i = 0; i < finished.length; i ++){
if(!finished[i]){
al.add(todo_list[i]);
}
}
String[] answer = new String [al.size()];
for(int i = 0; i < al.size(); i ++){
answer[i] = al.get(i);
}
return answer;
}
}
Java
복사