求助
  • 板块灌水区
  • 楼主JerryHSJ2
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/9/17 10:50
  • 上次更新2024/9/17 14:32:19
查看原帖
求助
1062060
JerryHSJ2楼主2024/9/17 10:50

大佬们看一下,我这个为什么会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));
    }
}
2024/9/17 10:50
加载中...