Skip to content

Commit 18de7ac

Browse files
committed
Jan 23
1 parent e75670c commit 18de7ac

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from itertools import product
2+
from typing import List
3+
4+
5+
class Solution:
6+
def countServers(self, grid: List[List[int]]) -> int:
7+
m, n = len(grid), len(grid[0])
8+
row_sums, col_sums = [0] * m, [0] * n
9+
servers = []
10+
11+
for x, y in product(range(m), range(n)):
12+
if grid[x][y] == 0:
13+
continue
14+
row_sums[x] += 1
15+
col_sums[y] += 1
16+
servers.append((x, y))
17+
18+
count = 0
19+
for x, y in servers:
20+
if row_sums[x] > 1 or col_sums[y] > 1:
21+
count += 1
22+
return count
23+
24+
25+
def main():
26+
grid = [[1, 0],
27+
[0, 1]]
28+
assert Solution().countServers(grid) == 0
29+
30+
grid = [[1, 0],
31+
[1, 1]]
32+
assert Solution().countServers(grid) == 3
33+
34+
grid = [[1, 1, 0, 0],
35+
[0, 0, 1, 0],
36+
[0, 0, 1, 0],
37+
[0, 0, 0, 1]]
38+
assert Solution().countServers(grid) == 4
39+
40+
41+
if __name__ == '__main__':
42+
main()

2025-01-January-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
| January 20 | [2661. First Completely Painted Row or Column](https://leetcode.com/problems/first-completely-painted-row-or-column/) | Medium | Solved |
2626
| January 21 | [2017. Grid Game](https://leetcode.com/problems/grid-game/) | Medium | Solved |
2727
| January 22 | [1765. Map of Highest Peak](https://leetcode.com/problems/map-of-highest-peak/) | Medium | Solved |
28-
| January 23 | []() | | |
28+
| January 23 | [1267. Count Servers that Communicate](https://leetcode.com/problems/count-servers-that-communicate/) | Medium | Solved |
2929
| January 24 | []() | | |
3030
| January 25 | []() | | |
3131
| January 26 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 4 | 4 | 0 |
43-
| Medium | 15 | 13 | 2 |
43+
| Medium | 16 | 14 | 2 |
4444
| Hard | 2 | 0 | 2 |

0 commit comments

Comments
 (0)