Skip to content

Commit

Permalink
대충 만든 자판 - level2
Browse files Browse the repository at this point in the history
  • Loading branch information
sey2 authored Feb 24, 2023
1 parent 09d1538 commit cdef3dd
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions programmers/RoughKeyboard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.util.*;

class Solution {
public int[] solution(String[] keymap, String[] targets) {
int[] answer = new int[targets.length];
int [] key = new int[26];

Arrays.fill(key, 9999);

for(int i=0; i<keymap.length; i++){
String str = keymap[i];

for(int j=0; j<keymap[i].length(); j++){
key[str.charAt(j) - 'A'] = Math.min(key[str.charAt(j) - 'A'], j+1);
}
}


loop:
for(int i=0; i<targets.length; i++){
int sum = 0;

for(int j=0; j<targets[i].length(); j++){
char c = targets[i].charAt(j);
if(key[c - 'A'] == 9999){
answer[i] = -1;
continue loop;
}else{
sum+= key[c - 'A'] ;
}
}

answer[i] = sum;
}
return answer;
}
}

0 comments on commit cdef3dd

Please sign in to comment.