Skip to content

Commit 5e3d94d

Browse files
authored
Create check-if-matrix-is-x-matrix.py
1 parent acbcb5d commit 5e3d94d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Python/check-if-matrix-is-x-matrix.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Time: O(n^2)
2+
# Space: O(1)
3+
4+
# array
5+
class Solution(object):
6+
def checkXMatrix(self, grid):
7+
"""
8+
:type grid: List[List[int]]
9+
:rtype: bool
10+
"""
11+
return all((i-j == 0 or i+j == len(grid)-1) == (grid[i][j] != 0) for i in xrange(len(grid)) for j in xrange(len(grid[0])))

0 commit comments

Comments
 (0)