957. Prison Cells After N Days Medium
1/**
2 * [957] Prison Cells After N Days
3 *
4 * There are 8 prison cells in a row and each cell is either occupied or vacant.
5 * Each day, whether the cell is occupied or vacant changes according to the following rules:
6 *
7 * If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
8 * Otherwise, it becomes vacant.
9 *
10 * Note that because the prison is a row, the first and the last cells in the row can't have two adjacent neighbors.
11 * You are given an integer array cells where cells[i] == 1 if the i^th cell is occupied and cells[i] == 0 if the i^th cell is vacant, and you are given an integer n.
12 * Return the state of the prison after n days (i.e., n such changes described above).
13 *
14 * Example 1:
15 *
16 * Input: cells = [0,1,0,1,1,0,0,1], n = 7
17 * Output: [0,0,1,1,0,0,0,0]
18 * Explanation: The following table summarizes the state of the prison on each day:
19 * Day 0: [0, 1, 0, 1, 1, 0, 0, 1]
20 * Day 1: [0, 1, 1, 0, 0, 0, 0, 0]
21 * Day 2: [0, 0, 0, 0, 1, 1, 1, 0]
22 * Day 3: [0, 1, 1, 0, 0, 1, 0, 0]
23 * Day 4: [0, 0, 0, 0, 0, 1, 0, 0]
24 * Day 5: [0, 1, 1, 1, 0, 1, 0, 0]
25 * Day 6: [0, 0, 1, 0, 1, 1, 0, 0]
26 * Day 7: [0, 0, 1, 1, 0, 0, 0, 0]
27 *
28 * Example 2:
29 *
30 * Input: cells = [1,0,0,1,0,0,1,0], n = 1000000000
31 * Output: [0,0,1,1,1,1,1,0]
32 *
33 *
34 * Constraints:
35 *
36 * cells.length == 8
37 * cells[i] is either 0 or 1.
38 * 1 <= n <= 10^9
39 *
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/prison-cells-after-n-days/
44// discuss: https://leetcode.com/problems/prison-cells-after-n-days/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49 pub fn prison_after_n_days(cells: Vec<i32>, n: i32) -> Vec<i32> {
50 vec![]
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_957() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.