-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExersize_One.java
More file actions
48 lines (41 loc) · 892 Bytes
/
Copy pathExersize_One.java
File metadata and controls
48 lines (41 loc) · 892 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
40
41
42
43
44
45
46
47
48
import java.util.Queue;
public class Exersize_One {
boolean isMirrorNumber(Queue<Integer> q, int m) {
for (int i = 0; i < m / 2; i++) {
int prev = q.remove();
q.add(prev);
int curr = q.remove();
q.add(curr);
int next = q.remove();
if (i % 2 == 0) {
int avg = (prev + next) / 2;
if (curr != avg) {
return false;
}
}
}
return true;
}
boolean nMirror(Queue<Integer> q, int m) {
if (m <= 2) {
return true;
}
int prev = q.remove();
q.add(prev);
int curr = q.remove();
q.add(curr);
for (int i = 1; i <= m - 2; i++) {
int next = q.remove();
q.add(next);
if (i % 2 == 0) {
int avg = (prev + next) / 2;
if (curr != avg) {
return false;
}
}
prev = curr;
curr = next;
}
return true;
}
}