반응형

완주하지 못한 선수: 해시 Lv.1

 

https://school.programmers.co.kr/learn/courses/30/lessons/42576

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

import java.util.HashMap;

class Solution {
    public String solution(String[] participant, String[] completion) {
        String answer = "";
        
       	HashMap<String, Integer> map = new HashMap<>();
		
		for(int i=0, l=participant.length;i<l;i++) {
			String key = participant[i];
			map.put(key, map.getOrDefault(key, 0)+1);
		}
		
		for(int i=0, l=completion.length;i<l;i++) {
			String key = completion[i];
			map.replace(key, map.get(key)-1);
		}
		
		return map.entrySet().stream().filter(e->e.getValue()==1).findFirst().get().getKey();
    }
}
반응형

'알고리즘 > 프로그래머스' 카테고리의 다른 글

덧칠하기  (0) 2024.04.06
둘만의 암호  (0) 2024.04.06
게임 맵 최단거리  (0) 2024.04.06
JadenCase 문자열 만들기  (0) 2024.04.06
최댓값과 최솟값  (0) 2024.03.27

+ Recent posts