0%

LeetCode-657

题目

结果

代码

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;
}
}

复杂度

时间复杂度:O(n)

空间复杂度:O(1)