1,题目
2,思路
左边-1,右边+1,上面-n,下面+n
可以得出最后结果
3,代码
class Solution3245 {
public int finalPositionOfSnake(int n, List<String> commands) {
int x = 0;
for (int i = 0; i < commands.size(); i++) {
if (commands.get(i).equals("RIGHT")) {
x++;
} else if (commands.get(i).equals("DOWN")) {
x += n;
} else if (commands.get(i).equals("UP")) {
x -= n;
} else {
x--;
}
}
return x;
}
}