1. java
import java.util.*;
class Solution {
public String solution(String[] participant, String[] completion) {
String answer = "";
HashMap<String,Integer> hMap = new HashMap<String,Integer>();
for(String c :completion){
if(hMap.containsKey(c)){
hMap.put(c, hMap.get(c)+1);
}else{
hMap.put(c, 1);
}
}
for(String p : participant){
if(hMap.containsKey(p)){
int tm = hMap.get(p) - 1;
if(tm == -1) return p;
else hMap.put(p,tm);
}else return p;
}
return answer;
}
}
2. python
def solution(participant, completion):
answer = ''
hDict = dict();
for c in completion:
if c in hDict:
hDict[c] += 1
else:
hDict[c] = 1
for p in participant:
if p in hDict:
hDict[p] -= 1
if hDict[p] == -1: return p
else:
return p
return answer
'백준 & 프로그래머스' 카테고리의 다른 글
[프로그래머스] [2019 카카오 개발자 겨울 인턴십] 크레인 인형뽑기 게임 java (0) | 2024.02.02 |
---|---|
프로그래머스. 둘만의 암호. Java and Python (0) | 2024.01.26 |
프로그래머스.교점에 별 만들기.Java and Python (0) | 2024.01.15 |
프로그래머스[2024 KAKAO WINTER INTERNSHIP]가장 많이 받은 선물.Java and Python (0) | 2024.01.10 |
뒤에 있는 큰 수 찾기 (0) | 2023.12.19 |
댓글