-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution657.java
More file actions
39 lines (38 loc) · 1008 Bytes
/
Copy pathSolution657.java
File metadata and controls
39 lines (38 loc) · 1008 Bytes
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
39
/**
* @Title: Solution657.java——
* @Package EasyCode_02
* @Description: TODO
* @author msdumin@gmail.com
* @date 2019年4月3日 下午9:31:44
* @version V1.0
*/
package EasyCode_02;
/**
* @ClassName: Solution657——机器人能否返回原点
* @Description: TODO
* @author msdumin@gmail.com
* @date 2019年4月3日 下午9:31:44
*/
public class Solution657 {
public static boolean judgeCircle(String moves) {
char[] arr = moves.toCharArray();
int[] table = new int[4];
for(int i = 0 ; i < arr.length ; i ++){
if(arr[i] == 'D')
table[arr[i] - 'D'] ++;
else if(arr[i] == 'U')
table[arr[i] - 'U' + 1] ++;
else if(arr[i] == 'R')
table[arr[i] - 'R' + 2] ++;
else
table[arr[i] - 'L' + 3] ++;
}
if(table[0] == table[1] && table[2] == table[3])
return true;
return false;
}
public static void main(String[] args) {
String moves = "UD";
System.out.println(judgeCircle(moves));
}
}