1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| class Solution { public boolean judgeCircle(String moves) { int x = 0, y = 0; for (char ch : moves.toCharArray()) { if (ch == 'R') { x++; } else if (ch == 'L') { x--; } else if (ch == 'U') { y--; } else if (ch == 'D') { y++; } } return x == 0 && y == 0; } }
|