์ฒด๊ฐ Level : โ
โ โ Review: ํ ํฌ๊ธฐ๋ฅผ ๋์ด์๋ ๋ฒ์๋ฅผ ์๊ฐํด์ผํ๋ค! |
๐ก
์ด๋ํ๋ค๋ณด๋ฉด ํ ํฌ๊ธฐ๋ฅผ ๋์ด์๋ ๋ฒ์๊ฐ ์๊ธฐ๊ธฐ ๋๋ฌธ์
์กฐ๊ฑด์์ ํตํด์ ํํฌ๊ธฐ์ ๋ค๋ค๋ฅด๋ฉด ๋์ด์ ์์ง์ผ ์ ์๊ฒ ํด์ผํ๋ค!!
class Solution {
public int[] solution(String[] keyinput, int[] board) {
int[] answer = {0,0};
int xmax = board[0]/2;
int ymax = board[1]/2;
for (String key : keyinput){
switch(key){
case "left":
if(answer[0] > -xmax){
answer[0] -= 1;
}
break;
case "right":
if(answer[0] < xmax){
answer[0] += 1;
}
break;
case "up":
if(answer[1] < ymax){
answer[1] += 1;
}
break;
case "down":
if(answer[1] > -ymax){
answer[1] -= 1;
}
break;
}
}
return answer;
}
}