[프로그래머스 Level 1] 대충 만든 자판
1분 읽기
풀이 1:
function solution(keymap, targets) {
const map = new Map();
keymap.forEach(keys => {
[...keys].forEach((key, j) => {
const count = j + 1;
const value = map.get(key);
if(!value || value && value > count){
map.set(key, count);
}
})
});
return targets.map(str => {
let total = 0;
for(let i = 0; i < str.length; i++){
if(!map.has(str[i])) return -1;
total += map.get(str[i]);
}
return total;
});
}Greedy10편 중 8번째
관련 글
4분 읽기
소수 구하기
소수 판별법과 소수를 구하는 알고리즘을 정리합니다.
1분 읽기
[프로그래머스 Level 2] 미로 탈출
프로그래머스 미로 탈출을 BFS로 풀이합니다.
1분 읽기
[프로그래머스 Level 2] 마법의 엘리베이터
프로그래머스 마법의 엘리베이터를 자리수 그리디로 풀이합니다.