Class Solution
-
- All Implemented Interfaces:
public final class Solution3142 - Check if Grid Satisfies Conditions.
Easy
You are given a 2D matrix
gridof sizem x n. You need to check if each cellgrid[i][j]is:Equal to the cell below it, i.e.
grid[i][j] == grid[i + 1][j](if it exists).Different from the cell to its right, i.e.
grid[i][j] != grid[i][j + 1](if it exists).
Return
trueif all the cells satisfy these conditions, otherwise, returnfalse.Example 1:
Input: grid = \[\[1,0,2],1,0,2]
Output: true
Explanation:
All the cells in the grid satisfy the conditions.
Example 2:
Input: grid = \[\[1,1,1],0,0,0]
Output: false
Explanation:
All cells in the first row are equal.
Example 3:
Input: grid = \[\[1],2,3]
Output: false
Explanation:
Cells in the first column have different values.
Constraints:
1 <= n, m <= 100 <= grid[i][j] <= 9
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleansatisfiesConditions(Array<IntArray> grid)-
-
Method Detail
-
satisfiesConditions
final Boolean satisfiesConditions(Array<IntArray> grid)
-
-
-
-