3142. Check if Grid Satisfies Conditions Easy

@problem@discussion
#Array#Matrix



1/**
2 * [3142] Check if Grid Satisfies Conditions
3 *
4 * You are given a 2D matrix grid of size m x n. You need to check if each cell grid[i][j] is:
5 * 
6 * 	Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists).
7 * 	Different from the cell to its right, i.e. grid[i][j] != grid[i][j + 1] (if it exists).
8 * 
9 * Return true if all the cells satisfy these conditions, otherwise, return false.
10 *  
11 * <strong class="example">Example 1:
12 * <div class="example-block">
13 * Input: <span class="example-io">grid = [[1,0,2],[1,0,2]]</span>
14 * Output: <span class="example-io">true</span>
15 * Explanation:
16 * <img alt="" src="https://assets.leetcode.com/uploads/2024/04/15/examplechanged.png" style="width: 254px; height: 186px;padding: 10px; background: #fff; border-radius: .5rem;" />
17 * All the cells in the grid satisfy the conditions.
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">grid = [[1,1,1],[0,0,0]]</span>
22 * Output: <span class="example-io">false</span>
23 * Explanation:
24 * <img alt="" src="https://assets.leetcode.com/uploads/2024/03/27/example21.png" style="width: 254px; height: 186px;padding: 10px; background: #fff; border-radius: .5rem;" />
25 * All cells in the first row are equal.
26 * </div>
27 * <strong class="example">Example 3:
28 * <div class="example-block">
29 * Input: <span class="example-io">grid = [[1],[2],[3]]</span>
30 * Output: <span class="example-io">false</span>
31 * Explanation:
32 * <img alt="" src="https://assets.leetcode.com/uploads/2024/03/31/changed.png" style="width: 86px; height: 277px;padding: 10px; background: #fff; border-radius: .5rem;" />
33 * Cells in the first column have different values.
34 * </div>
35 *  
36 * Constraints:
37 * 
38 * 	1 <= n, m <= 10
39 * 	0 <= grid[i][j] <= 9
40 * 
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/check-if-grid-satisfies-conditions/
45// discuss: https://leetcode.com/problems/check-if-grid-satisfies-conditions/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50    pub fn satisfies_conditions(grid: Vec<Vec<i32>>) -> bool {
51        false
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_3142() {
63    }
64}
65


Back
© 2025 bowen.ge All Rights Reserved.