본문 바로가기

Coding Test/프로그래머스

[프로그래머스/자바] 할 일 목록

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]);
        }
        String[] result = new String[list.size()];
        for(int i=0; i< result.length; i++){
            result[i] = list.get(i);
        }
        return result;
    }
}

import java.util.stream.IntStream;

class Solution {
    public String[] solution(String[] todo_list, boolean[] finished) {
        return IntStream.range(0, finished.length).filter(i -> !finished[i]).mapToObj(i -> todo_list[i])
                .toArray(String[]::new);
    }
}