-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathQuestion3.java
More file actions
39 lines (32 loc) · 1 KB
/
Question3.java
File metadata and controls
39 lines (32 loc) · 1 KB
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
package edu.nd.se2018.homework.hwk1;
import java.util.ArrayList;
import java.util.List;
public class Question3 {
public Question3() {
}
public int getMirrorCount(int[] numbers) {
int res = 0;
for (int i = 0; i < numbers.length; i++) {
ArrayList tempList = new ArrayList();
for (int j = 0; j < numbers.length - i; j++) {
tempList.add(numbers[i + j]);
if (isMirrow(tempList)) {
int tempRes = tempList.size();
if (tempRes > res) {
res = tempRes;
}
}
}
}
System.out.println(res);
return res;
}
public boolean isMirrow(List numbers) {
for (int i = 0; i < Math.floor(numbers.size() / 2); i++) {
if (numbers.get(i) != numbers.get(numbers.size() - 1 - i)) {
return false;
}
}
return true;
}
}