쉬움 0명 해결 정답률 0%

To-Do List

Keep a list of tasks: add them, mark them done, remove them and report what is still pending.

배우게 될 내용

  • Keep tasks with a title and a done flag
  • Find an item by title before changing it
  • Filter the items that are still pending

문제

번역본 보기

A to-do app keeps tasks in a typed collection such as List<T>. Each task has a title and a done flag.

Start with an empty list and process the operations, each a command and a title (the title is everything after the first space):

  • add <title>: add a pending task at the end, unless a task with that title already exists.
  • done <title>: mark that task as done (no effect if it does not exist).
  • remove <title>: delete that task (no effect if it does not exist).

Implement todo_list(operations).

Input

operations: The operations. Titles may contain spaces and are compared exactly.

Output

Return the titles of the tasks that are not done, in the order they were added.

제약 조건

0 ≤ number of operations ≤ 10,000

Titles have 1 to 50 characters

예시

예시 1
입력:
operations = ["add Buy milk", "add Write report", "done Buy milk", "add Call Ada"]

예상 출력:
expected = ["Write report", "Call Ada"]
입력:
std::vector<std::string> operations = {"add Buy milk", "add Write report", "done Buy milk", "add Call Ada"};

예상 출력:
std::vector<std::string> expected = {"Write report", "Call Ada"};
입력:
string[] operations = new string[] {"add Buy milk", "add Write report", "done Buy milk", "add Call Ada"};

예상 출력:
string[] expected = new string[] {"Write report", "Call Ada"};

설명

Buy milk is done, so only the other two remain, in the order they were added: ["Write report", "Call Ada"].

예시 2
입력:
operations = ["add Gym", "add Gym", "remove Gym", "done Gym"]

예상 출력:
expected = []
입력:
std::vector<std::string> operations = {"add Gym", "add Gym", "remove Gym", "done Gym"};

예상 출력:
std::vector<std::string> expected = {};
입력:
string[] operations = new string[] {"add Gym", "add Gym", "remove Gym", "done Gym"};

예상 출력:
string[] expected = new string[] {};

설명

The second add is ignored because Gym already exists; removing it leaves nothing, and done on a missing task does nothing: [].

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

Store each task as a small record of title and done.

힌트 2

Look a task up by its exact title before adding, completing or removing it.

힌트 3

At the end keep only the tasks that are not done, in insertion order.

예상 복잡도

O(n²) time, O(n) extra space

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.