您当前的位置: 首页 >  服务器

LeetCode Algorithm 1267. 统计参与通信的服务器

发布时间:2022-01-19 21:44:56 ,浏览量:0

1267. 统计参与通信的服务器

Ideas

这题不想写题解了,想了半天的DFS和并查集,憋了半小时没写出来,一看题解跟我说计数。

我好难受。。。。

Code Python
from typing import List class Solution: def countServers(self, grid: List[List[int]]) -> int: rows, cols, ans = len(grid), len(grid[0]), 0 cnt_row, cnt_col = [0] * rows, [0] * cols for i in range(rows): for j in range(cols): if grid[i][j] == 1: cnt_row[i] += 1 cnt_col[j] += 1 for i in range(rows): for j in range(cols): if grid[i][j] == 1 and (cnt_row[i] > 1 or cnt_col[j] > 1): ans += 1 return ans if __name__ == '__main__': print(Solution().countServers([[1, 0], [1, 1]])) 
关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    108697博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.2949s