-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
class Pos{ | ||
int x; | ||
int y; | ||
|
||
public Pos(int y, int x){ | ||
this.y = y; | ||
this.x = x; | ||
} | ||
} | ||
|
||
class Solution { | ||
public static String solution(int[] numbers, String hand) { | ||
String answer = ""; | ||
Pos left = new Pos(3, 0); // *์์ ์์ | ||
Pos right = new Pos(3, 2); // #์์ ์์ | ||
Pos key[] = new Pos[10]; | ||
|
||
int cnt = 1; | ||
key[0] = new Pos(3,1); // 0 ์์น | ||
|
||
for(int i=0; i<3; i++){ | ||
for(int j=0; j<3; j++) | ||
key[cnt++] = new Pos(i,j); | ||
} | ||
|
||
for(int i=0; i<numbers.length; i++){ | ||
Pos next = key[numbers[i]]; | ||
|
||
if((next.y == 0 || next.y == 1 || next.y == 2) && next.x == 0) { // 1, 4, 7 ์ธ ๊ฒฝ์ฐ | ||
left = next; | ||
answer += "L"; | ||
} | ||
else if((next.y == 0 || next.y == 1 || next.y == 2) && next.x == 2) { // 3, 6, 9์ธ ๊ฒฝ์ฐ | ||
right = next; | ||
answer += "R"; | ||
} | ||
else{ // 2, 5, 8, 0 ์ธ ๊ฒฝ์ฐ | ||
int leftDis = Math.abs(left.x - next.x) + Math.abs(left.y - next.y); | ||
int rightDis = Math.abs(right.x - next.x) + Math.abs(right.y - next.y); | ||
|
||
if(hand.equals("left")) { | ||
if(leftDis<= rightDis){ | ||
answer+= "L"; | ||
left = next; | ||
}else{ | ||
answer +="R"; | ||
right = next; | ||
} | ||
|
||
} | ||
else if(hand.equals("right")) { | ||
if(leftDis >= rightDis){ | ||
answer+= "R"; | ||
right=next; | ||
}else{ | ||
answer += "L"; | ||
left = next; | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
return answer; | ||
} | ||
} |