2579. Count Total Number of Colored Cells Medium

@problem@discussion
#Math



1/**
2 * [2579] Count Total Number of Colored Cells
3 *
4 * There exists an infinitely large two-dimensional grid of uncolored unit cells. You are given a positive integer n, indicating that you must do the following routine for n minutes:
5 * 
6 * 	At the first minute, color any arbitrary unit cell blue.
7 * 	Every minute thereafter, color blue every uncolored cell that touches a blue cell.
8 * 
9 * Below is a pictorial representation of the state of the grid after minutes 1, 2, and 3.
10 * <img alt="" src="https://assets.leetcode.com/uploads/2023/01/10/example-copy-2.png" style="width: 500px; height: 279px;" />
11 * Return the number of colored cells at the end of n minutes.
12 *  
13 * <strong class="example">Example 1:
14 * 
15 * Input: n = 1
16 * Output: 1
17 * Explanation: After 1 minute, there is only 1 blue cell, so we return 1.
18 * 
19 * <strong class="example">Example 2:
20 * 
21 * Input: n = 2
22 * Output: 5
23 * Explanation: After 2 minutes, there are 4 colored cells on the boundary and 1 in the center, so we return 5. 
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= n <= 10^5
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/count-total-number-of-colored-cells/
34// discuss: https://leetcode.com/problems/count-total-number-of-colored-cells/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn colored_cells(n: i32) -> i64 {
40        
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_2579() {
52    }
53}
54


Back
© 2025 bowen.ge All Rights Reserved.