Java代码:
java
class Solution {
public boolean judgeCircle(String moves) {
int[] x = {0, 0, -1, 1};
int[] y = {1, -1, 0, 0};
String str = "UDLR";
int xx = 0, yy = 0;
for (int i = 0; i < moves.length(); i++) {
xx += x[str.indexOf(moves.charAt(i))];
yy += y[str.indexOf(moves.charAt(i))];
}
return xx == 0 && yy == 0;
}
}