3142. Check if Grid Satisfies Conditions
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 43% Topics: Array, Matrix
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(m * n)
# Space: O(1)
# array
class Solution(object):
def satisfiesConditions(self, grid):
"""
:type grid: List[List[int]]
:rtype: bool
"""
return (all(grid[i][j] == grid[i+1][j] for j in xrange(len(grid[0])) for i in xrange(len(grid)-1)) and
all(grid[0][j] != grid[0][j+1] for j in xrange(len(grid[0])-1)))
Solution from kamyu104/LeetCode-Solutions · MIT