-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirReduction.java
More file actions
27 lines (25 loc) · 875 Bytes
/
DirReduction.java
File metadata and controls
27 lines (25 loc) · 875 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
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created by Lukas on 2017-02-06.
*/
public class DirReduction {
public static String[] dirReduc(String[] arr) {
List<String> res = new ArrayList<String>(Arrays.asList(arr));
int i = 0;
while(i + 1 < res.size()){
if((res.get(i) == "NORTH" && res.get(i+1) == "SOUTH") || (res.get(i) == "SOUTH" && res.get(i+1) == "NORTH")){
res.remove(i + 1);
res.remove(i);
i = 0;
} else if ((res.get(i) == "EAST" && res.get(i+1) == "WEST") || (res.get(i) == "WEST" && res.get(i+1) == "EAST")) {
res.remove(i + 1);
res.remove(i);
i = 0;
} else i++;
}
String[] resArr = new String[res.size()];
return res.toArray(resArr);
}
}