Count Servers that Communicate LeetCode solution in Python

1
class Solution:
2
def countServers(self, grid: List[List[int]]) -> int:
3
def helper(row, col, count):
4
for c in range(len(grid[0])):
5
if c == col:
6
continue
7
if grid[row][c] == 1:
8
count += 1
9
return count
10
for r in range(len(grid)):
11
if r == row:
12
continue
13
if grid[r][col] == 1:
14
count += 1
15
return count
16
return count
17

18
count = 0
19
for row in range(len(grid)):
20
for col in range(len(grid[0])):
21
if grid[row][col] == 1:
22
count = helper(row, col, count)
23
return count

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0