[프로그래머스/Java] Lv.0 할 일 목록

febCho·2024년 3월 11일
0

코딩테스트

목록 보기
66/253
post-thumbnail

문제

오늘 해야 할 일이 담긴 문자열 배열 todo_list와 각각의 일을 지금 마쳤는지를 나타내는 boolean 배열 finished가 매개변수로 주어질 때, todo_list에서 아직 마치지 못한 일들을 순서대로 담은 문자열 배열을 return 하는 solution 함수를 작성해 주세요.

- 제한사항

  • 1 ≤ todo_list의 길이 1 ≤ 100
  • 2 ≤ todo_list의 원소의 길이 ≤ 20
  • todo_list의 원소는 영소문자로만 이루어져 있습니다.
  • todo_list의 원소는 모두 서로 다릅니다.
  • finished[i]는 true 또는 false이고 true는 todo_list[i]를 마쳤음을, false는 아직 마치지 못했음을 나타냅니다.
  • 아직 마치지 못한 일이 적어도 하나 있습니다.

풀이

import java.util.*;

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

결과

profile
Done is better than perfect.

0개의 댓글