-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path대충 만든 자판.java
28 lines (26 loc) · 1.01 KB
/
대충 만든 자판.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.*;
class Solution {
public int[] solution(String[] keymap, String[] targets) {
int[] answer = new int[targets.length];
HashMap<Character, Integer> dict = new HashMap<Character, Integer>();
for(int i=0; i<keymap.length; i++){
for(int j=0; j<keymap[i].length(); j++){
if(!dict.containsKey(keymap[i].charAt(j))) dict.put(keymap[i].charAt(j),j+1);
if(dict.containsKey(keymap[i].charAt(j)) && dict.get(keymap[i].charAt(j))>j+1) dict.put(keymap[i].charAt(j),j+1);
}
}
int count=0;
for(int i=0; i<targets.length;i++){
count=0;
for(int j=0; j<targets[i].length();j++){
if(dict.containsKey(targets[i].charAt(j))) count+=dict.get(targets[i].charAt(j));
else{
answer[i]=-1;
break;
}
if(j==targets[i].length()-1) answer[i]=count;
}
}
return answer;
}
}