题目描述:

自己的提交:

class Solution:
def countServers(self, grid: List[List[int]]) -> int:
from collections import Counter
m,n = len(grid),len(grid[])
falg = set()
set1,set2 = Counter(),Counter()
res =
for i in range(m):
for j in range(n):
if grid[i][j] == :
if set1[i] > or set2[j] > :
res +=
if set1[i] == :
for x in falg:
if x[] == i:
res +=
falg.remove(x)
break
if set2[j] == :
for x in falg:
if x[] == j:
res +=
falg.remove(x)
break
else:
falg.add((i,j))
set1[i] +=
set2[j] +=
return res

优化:

class Solution:
def countServers(self, grid: List[List[int]]) -> int:
n,m=len(grid),len(grid[0])
col=[0]*m
row=[0]*n
for i in range(n):
for j in range(m):
if grid[i][j]:
row[i]+=1
col[j]+=1
ans=0
for i in range(n):
for j in range(m):
if grid[i][j] and (col[j]>1 or row[i]>1):
ans+=1
return ans

leetcode-164周赛-1267-统计参与通信的服务器的更多相关文章

  1. LeetCode 5272. 5272. 统计参与通信的服务器 Count Servers that Communicate

    地址 https://leetcode-cn.com/problems/count-servers-that-communicate/ 题目描述这里有一幅服务器分布图,服务器的位置标识在 m * n  ...

  2. TCP通信的客户端代码实现和TCP通信的服务器代码实现

    TCP通信的客户端代码实现 package com.yang.Test.ServerStudy; import java.io.*; import java.net.Socket; /** * TCP ...

  3. [LeetCode] Count Binary Substrings 统计二进制子字符串

    Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...

  4. [leetcode] 204. Count Primes 统计小于非负整数n的素数的个数

    题目大意 https://leetcode.com/problems/count-primes/description/ 204. Count Primes Count the number of p ...

  5. [LeetCode] 164. Maximum Gap 求最大间距

    Given an unsorted array, find the maximum difference between the successive elements in its sorted f ...

  6. LeetCode 164. Maximum Gap[翻译]

    164. Maximum Gap 164. 最大间隔 Given an unsorted array, find the maximum difference between the successi ...

  7. Java实现 LeetCode 164 最大间距

    164. 最大间距 给定一个无序的数组,找出数组在排序之后,相邻元素之间最大的差值. 如果数组元素个数小于 2,则返回 0. 示例 1: 输入: [3,6,9,1] 输出: 3 解释: 排序后的数组是 ...

  8. LeetCode双周赛#35

    1589. 所有排列中的最大和 #差分 #贪心 题目链接 题意 给定整数数组nums,以及查询数组requests,其中requests[i] = [starti, endi] .第i个查询求 num ...

  9. LeetCode双周赛#34

    5492. 分割字符串的方案数 #组合公式 #乘法原理 #区间分割 题目链接 题意 给定01二进制串\(s\),可将\(s\)分割为三个非空 字符串\(s_1,s_2,s_3\),即(\(s_1+s_ ...

随机推荐

  1. 【串线篇】REST风格的请求格式

    1.什么是rest 答出这两点就够了: 1.1 统一接口 rest其实是基于HTTP的,四种方式. RESTful架构风格规定,数据的元操作,即CRUD(create, read, update和de ...

  2. webpack 学习三 模式

    开发环境(development)和生产环境(production)的构建目标差异很大.在开发环境中,我们需要具有强大的.具有实时重新加载(live reloading)或热模块替换(hot modu ...

  3. php操作redis常用方法代码示例

     redis 的连接 描述:实例连接到一个Redis. 参数:host: string,port: int 返回值:BOOL 成功返回:TRUE;失败返回:FALSE $redis = new Red ...

  4. Concurrent - 线程池

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11426981.html ThreadPoolExecutor底层方法参数: @param corePo ...

  5. 如何在Mac上将视频刻录到DVD / ISO文件

    如果您希望将喜爱的视频转换为DVD / Blu-ray光盘以进行物理备份或播放,则Mac版Wondershare UniConverter可以专业地完成任务.今天的教程就是如何在Mac上轻松刻录DVD ...

  6. node快速起web服务器

    首选,安装http-server模块 npm install http-server -g 在需要打开的静态页面的目录下,开启服务即可 http-server

  7. 【leetcode】934. Shortest Bridge

    题目如下: In a given 2D binary array A, there are two islands.  (An island is a 4-directionally connecte ...

  8. hdu1166 敌兵布阵 (线段树单点更新)

    Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营 地,Derek和Tidy的任务就是要监视这 ...

  9. kubernetes使用kubeadm升级集群

    升级前准本  官网: https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-upgrade/查看可升级的组件 [root@h ...

  10. redis常用命令-2

    redis常用命令 type your_key #查看Key类型 del your_key #删除key keys * #所有key info #信息 /usr/local/bin/redis-cli ...