forked from morethink/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest2.java
More file actions
72 lines (69 loc) · 2.27 KB
/
Test2.java
File metadata and controls
72 lines (69 loc) · 2.27 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package algorithm.sort;
import java.util.LinkedList;
import java.util.Queue;
/**
* @author 李文浩
* @date 2018/11/16
*/
public class Test2 {
public static void main(String[] args) {
String s1 = "12ddddd3###";
Queue<Integer> queue1 = new LinkedList<>();
int cycle = 0;
for (int i = 0; i < s1.length(); i++) {
if (s1.charAt(i) == '#') {
if (cycle > 0) {
for (int j = 0; j < cycle; j++) {
((LinkedList<Integer>) queue1).pop();
((LinkedList<Integer>) queue1).pop();
}
for (int j = cycle; j >= 0; j--) {
((LinkedList<Integer>) queue1).push(i - (2 * j + 1));
((LinkedList<Integer>) queue1).push(i - (2 * j));
}
} else {
queue1.offer(i - 1);
queue1.offer(i);
}
cycle++;
} else {
cycle = 0;
}
}
String s2 = "dddd###DDDD";
cycle = 0;
Queue<Integer> queue2 = new LinkedList<>();
for (int i = 0; i < s2.length(); i++) {
if (s1.charAt(i) == '#') {
if (cycle > 0) {
for (int j = 0; j < cycle; j++) {
((LinkedList<Integer>) queue2).pop();
((LinkedList<Integer>) queue2).pop();
}
for (int j = cycle; j >= 0; j--) {
((LinkedList<Integer>) queue2).push(i - (2 * j + 1));
((LinkedList<Integer>) queue2).push(i - (2 * j));
}
} else {
queue2.offer(i - 1);
queue2.offer(i);
}
cycle++;
} else {
cycle = 0;
}
}
boolean result = false;
int i = 0, j = 0;
while (i <= s1.length() && j < s2.length()) {
if (i == queue1.peek()) {
((LinkedList<Integer>) queue1).pop();
}
if (j == queue2.peek()) {
((LinkedList<Integer>) queue1).pop();
}
i++;
j++;
}
}
}