[카카오 인턴] 키패드 누르기

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class Solution {
    public String solution(int[] numbers, String hand) {
        List<String> listNumbers = new ArrayList<>();

        int X1_L = 0;
        int Y1_L = 3;

        int X1_R = 2;
        int Y1_R = 3;

        for (int i = 0; i < numbers.length; i++) {

            if (numbers[i] == 1 || numbers[i] == 4 || numbers[i] == 7) {

                listNumbers.add("L");

                switch (numbers[i]) {

                    case 1:
                        X1_L = 0;

                        Y1_L = 0;
                        break;

                    case 4:
                        X1_L = 0;

                        Y1_L = 1;
                        break;

                    case 7:
                        X1_L = 0;

                        Y1_L = 2;
                        break;
                }

            } else if (numbers[i] == 3 || numbers[i] == 6 || numbers[i] == 9) {

                listNumbers.add("R");

                switch (numbers[i]) {
                    case 3:
                        X1_R = 2;
                        Y1_R = 0;
                        break;
                    case 6:
                        X1_R = 2;

                        Y1_R = 1;
                        break;
                    case 9:
                        X1_R = 2;

                        Y1_R = 2;

                        break;
                }


            } else {
                int x1 = 0;
                int y1 = 0;

                switch (numbers[i]) {
                    case 2:
                        x1 = 1;
                        y1 = 0;
                        break;
                    case 5:
                        x1 = 1;
                        y1 = 1;
                        break;

                    case 8:
                        x1 = 1;
                        y1 = 2;
                        break;
                    case 0:
                        x1 = 1;
                        y1 = 3;
                        break;
                }

                int leftValue = Math.abs(X1_L - x1) + Math.abs(Y1_L - y1);

                int rightValue = Math.abs(X1_R - x1) + Math.abs(Y1_R - y1);


                if (leftValue == rightValue) {
                    if (hand.equals("left")) {

                        listNumbers.add("L");
                        X1_L = x1;
                        Y1_L = y1;

                    } else {

                        listNumbers.add("R");
                        X1_R = x1;
                        Y1_R = y1;

                    }
                } else if (leftValue > rightValue) {

                    listNumbers.add("R");
                    X1_R = x1;
                    Y1_R = y1;

                } else {

                    listNumbers.add("L");
                    X1_L = x1;
                    Y1_L = y1;

                }
            }

        }
String answer = String.join("", listNumbers);
        return answer;
    }
}