-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJudgeRoute.java
38 lines (32 loc) · 940 Bytes
/
JudgeRoute.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class JudgeRoute {
public static void main(String[] args) {
String moves = "LDRRLRUULRLD";
boolean pos = checkPos(moves);
System.out.println("Returned to the original pos: " + pos);
}
private static boolean checkPos(String moves) {
int n = moves.length();
int countL = 0;
int countR = 0;
int countU = 0;
int countD = 0;
for (int i = 0; i < n; i++) {
if (moves.charAt(i) == 'U') {
countU++;
}
if (moves.charAt(i) == 'D') {
countD++;
}
if (moves.charAt(i) == 'L') {
countL++;
}
if (moves.charAt(i) == 'R') {
countR++;
}
}
if (countU == countD && countL == countR) {
return true;
}
return false;
}
}