Skip to content

Commit efbd8eb

Browse files
committed
add sol
1 parent f3c7485 commit efbd8eb

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

leetcode/daily/1267/sol.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
from typing import List
3+
4+
class Solution:
5+
def countServers(self, grid: List[List[int]]) -> int:
6+
m = len(grid)
7+
n = len(grid[0])
8+
9+
row = [0] * m
10+
col = [0] * n
11+
12+
# count the number of servers in each row and column
13+
for i in range(m):
14+
for j in range(n):
15+
if grid[i][j] == 1:
16+
row[i] += 1
17+
col[j] += 1
18+
19+
# count the number of servers that are connected
20+
count = 0
21+
for i in range(m):
22+
for j in range(n):
23+
if grid[i][j] == 1 and (row[i] > 1 or col[j] > 1):
24+
count += 1
25+
26+
return count
27+
28+
if __name__ == "__main__":
29+
solution = Solution()
30+
grid = [[1, 1, 0, 0], [0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
31+
result = solution.countServers(grid)
32+
print(result)

0 commit comments

Comments
 (0)