import java.util.*;
class Solution {
public int[] solution(String[] keymap, String[] targets) {
int[] answer = new int[targets.length];
HashMap <Character, Integer> hm = new HashMap <Character, Integer>();
for(int i = 0; i < keymap.length; i++){
for(int j = 0; j < keymap[i].length(); j++){
if(hm.get(keymap[i].charAt(j)) == null || hm.get(keymap[i].charAt(j)) > j+1)
hm.put(keymap[i].charAt(j), j+1);
}
}
//System.out.println(hm.size());
for(int i = 0; i < targets.length; i++){
int sum = 0;
for(int j = 0; j < targets[i].length(); j++){
if(hm.get(targets[i].charAt(j)) != null)
sum += hm.get(targets[i].charAt(j));
else {
sum = -1;
break;
}
}
answer[i] = sum;
}
return answer;
}
}
거의 한번만에 통과! yay 신난다