Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Jan 23, 2025
1 parent f3c7485 commit efbd8eb
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions leetcode/daily/1267/sol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

from typing import List

class Solution:
def countServers(self, grid: List[List[int]]) -> int:
m = len(grid)
n = len(grid[0])

row = [0] * m
col = [0] * n

# count the number of servers in each row and column
for i in range(m):
for j in range(n):
if grid[i][j] == 1:
row[i] += 1
col[j] += 1

# count the number of servers that are connected
count = 0
for i in range(m):
for j in range(n):
if grid[i][j] == 1 and (row[i] > 1 or col[j] > 1):
count += 1

return count

if __name__ == "__main__":
solution = Solution()
grid = [[1, 1, 0, 0], [0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
result = solution.countServers(grid)
print(result)

0 comments on commit efbd8eb

Please sign in to comment.