|
|
|
@ -18,16 +18,14 @@ public class Code01_Light {
|
|
|
|
|
if (index == str.length) { // 结束的时候
|
|
|
|
|
for (int i = 0; i < str.length; i++) {
|
|
|
|
|
if (str[i] != 'X') { // 当前位置是点的话
|
|
|
|
|
if (!lights.contains(i - 1)
|
|
|
|
|
&& !lights.contains(i)
|
|
|
|
|
&& !lights.contains(i + 1)) {
|
|
|
|
|
if (!lights.contains(i - 1) && !lights.contains(i) && !lights.contains(i + 1)) {
|
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return lights.size();
|
|
|
|
|
} else { // str还没结束
|
|
|
|
|
// i X .
|
|
|
|
|
// i X .
|
|
|
|
|
int no = process(str, index + 1, lights);
|
|
|
|
|
int yes = Integer.MAX_VALUE;
|
|
|
|
|
if (str[index] == '.') {
|
|
|
|
@ -41,20 +39,20 @@ public class Code01_Light {
|
|
|
|
|
|
|
|
|
|
public static int minLight2(String road) {
|
|
|
|
|
char[] str = road.toCharArray();
|
|
|
|
|
int index = 0;
|
|
|
|
|
int i = 0;
|
|
|
|
|
int light = 0;
|
|
|
|
|
while (index < str.length) {
|
|
|
|
|
if (str[index] == 'X') {
|
|
|
|
|
index++;
|
|
|
|
|
} else { // i -> .
|
|
|
|
|
while (i < str.length) {
|
|
|
|
|
if (str[i] == 'X') {
|
|
|
|
|
i++;
|
|
|
|
|
} else {
|
|
|
|
|
light++;
|
|
|
|
|
if (index + 1 == str.length) {
|
|
|
|
|
if (i + 1 == str.length) {
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
if (str[index + 1] == 'X') {
|
|
|
|
|
index = index + 2;
|
|
|
|
|
} else { // 有i位置 i+ 1 X .
|
|
|
|
|
if (str[i + 1] == 'X') {
|
|
|
|
|
i = i + 2;
|
|
|
|
|
} else {
|
|
|
|
|
index = index + 3;
|
|
|
|
|
i = i + 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|