Post

[Programmers] #181885 - 할 일 목록 [Java][C++][Python]

[Programmers] #181885 - 할 일 목록 [Java][C++][Python]

문제 링크


1. 아이디어

아직 마치지 못한 일, 즉 finished가 false인 위치의 원소를 앞에서부터 차례로 모으면 입력 순서가 그대로 유지되므로 따로 정렬할 필요가 없다.


2. 코드

풀이 [Java][C++][Python]

1
2
3
4
5
6
7
8
9
10
11
12
import java.util.*;

class Solution {
    public String[] solution(String[] todo_list, boolean[] finished) {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < finished.length; i++) {
            if (!finished[i]) list.add(todo_list[i]);
        }

        return list.toArray(new String[0]);
    }
}
1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;

vector<string> solution(vector<string> todo_list, vector<bool> finished) {
    vector<string> v;
    for (int i = 0; i < todo_list.size(); i++) {
        if (!finished[i]) v.push_back(todo_list[i]);
    }

    return v;
}
1
2
def solution(todo_list, finished):
    return [todo for todo, done in zip(todo_list, finished) if not done]

This post is licensed under CC BY 4.0 by the author.