Playground/자바문제집

[프로그래머스] 완주하지 못한 선수

미숫가루설탕많이 2023. 5. 13. 16:36
import java.util.*;

class Solution {
    public String solution(String[] participant, String[] completion) {
        String answer = "";
        
        HashMap<String, Integer> hm = new HashMap<>();
        
        for (String str : completion) {
            if (hm.containsKey(str)) {
                hm.put(str, hm.get(str) + 1);
            } else {
                hm.put(str, 1);
            }
        }
        
        for (String str : participant) {
            if (hm.containsKey(str)) {
                if (hm.get(str) > 0) {
                    hm.put(str, hm.get(str) - 1);
                } else {
                    answer = str;
                    break;
                }
            }
            else {
                answer = str;
                break;
            }
        }
        return answer;
    }
}

'Playground > 자바문제집' 카테고리의 다른 글

[백준] 2720번  (0) 2023.05.14
[프로그래머스] 올바른 괄호  (0) 2023.05.13
[프로그래머스] 문자열 바꿔서 찾기  (0) 2023.05.09
[백준] 1427번  (0) 2023.04.10
[백준] 11286번  (0) 2023.04.07