class Solution {
public String[] solution(String[] todo_list, boolean[] finished) {
String[] answer = {};
return answer;
}
}
해결법
방법 1
import java.util.*;
class Solution {
public List solution(String[] todo_list, boolean[] finished) {
List<String> answer = new ArrayList<>();
for (int i = 0; i < todo_list.length; i++) {
if (finished[i] == false) {
answer.add(todo_list[i]);
}
}
return answer;
}
}
방법 2
import java.util.*;
class Solution {
public String[] solution(String[] todo_list, boolean[] finished) {
ArrayList <String> str = new ArrayList<>();
for (int i = 0; i < finished.length; i ++) {
if (!finished[i]) {
str.add(todo_list[i]);
}
}
String[] answer = new String[str.size()];
for (int i = 0; i < str.size(); i ++) {
answer[i] = str.get(i);
}
return answer;
}
}
방법 3
class Solution {
public String[] solution(String[] todo_list, boolean[] finished) {
String[] temp = new String[todo_list.length];
int count = 0;
for (int i = 0; i < todo_list.length; i++) {
if (!finished[i]) {
temp[count++] = todo_list[i];
}
}
String[] answer = new String[count];
for (int i = 0; i < count; i++) {
answer[i] = temp[i];
}
return answer;
}
}
할 일 목록 Lv. 0