import java.lang.Math;
class Solution {
String answer = "";
static int[][] keypad = new int[4][3];
public String solution(int[] numbers, String hand) {
int len = numbers.length;
int num;
int[] left = new int[2];
left[0] = 3;
left[1] = 0;
int[] right = new int[2];
right[0] = 3;
right[1] = 2;
int[] dest = new int[2];
int left_distance = 0;
int right_distance = 0;
for(int i = 0 ; i < len ; i++){
num = numbers[i];
if(num ==0 ) num = 11;
if(num == 1 || num == 4 || num == 7 ){
left[0] = num/3;
left[1] = 0;
answer+='L';
}else if(num == 3 || num == 6 || num == 9){
right[0] = (num/3)-1;
right[1] = 2;
answer+='R';
}else{
dest[0] = num/3;
dest[1] = 1;
left_distance = Math.abs(left[0] - dest[0]) + Math.abs(left[1] - dest[1]);
right_distance = Math.abs(right[0] - dest[0]) + Math.abs(right[1] - dest[1]);
if(left_distance > right_distance){
right[0] = dest[0];
right[1] = dest[1];
answer+='R';
}else if(left_distance == right_distance) {
if(hand.equals("left")){
left[0] = dest[0];
left[1] = dest[1];
answer+='L';
}else if(hand.equals("right")){
right[0] = dest[0];
right[1] = dest[1];
answer+='R';
}
}else if(left_distance < right_distance){
left[0] = dest[0];
left[1] = dest[1];
answer+='L';
}
}
}
return answer;
}
}
킹받는 문제