Skip to content

Commit 117761e

Browse files
authored
Create special-positions-in-a-binary-matrix.py
1 parent d282f5f commit 117761e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Time: O(n^2)
2+
# Space: O(n)
3+
4+
class Solution(object):
5+
def numSpecial(self, mat):
6+
"""
7+
:type mat: List[List[int]]
8+
:rtype: int
9+
"""
10+
rows, cols = [0]*len(mat), [0]*len(mat[0])
11+
for i in xrange(len(rows)):
12+
for j in xrange(len(cols)):
13+
if mat[i][j]:
14+
rows[i] += 1
15+
cols[j] += 1
16+
result = 0
17+
for i in xrange(len(rows)):
18+
for j in xrange(len(cols)):
19+
if mat[i][j] == rows[i] == cols[j] == 1:
20+
result += 1
21+
return result

0 commit comments

Comments
 (0)