大佬们看一下,我这个为什么会RE
import java.util.Arrays;
class Solution2 {
public static int[] streetLight(int[] initialState, int M) {
int[] light = initialState;
for (int day = 0; day < M; day++) {
int[] nextDay = new int[light.length];
nextDay[0] = 0;
nextDay[light.length - 1] = 0;
for (int i = 1; i < light.length - 1; i++) {
if (light[i - 1] == light[i + 1]) {
nextDay[i] = 0;
} else {
nextDay[i] = 1;
}
}
light = nextDay;
}
return light;
}
public static void main(String[] args) {
int[] initialState = new int[]{0, 1, 0, 1, 0, 1, 1, 0};
int M = 3;
int[] resultState = streetLight(initialState, M);
System.out.println(Arrays.toString(resultState));
}
}