leetcode-164周赛-1267-统计参与通信的服务器
题目描述:



自己的提交:
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-统计参与通信的服务器的更多相关文章
- LeetCode 5272. 5272. 统计参与通信的服务器 Count Servers that Communicate
地址 https://leetcode-cn.com/problems/count-servers-that-communicate/ 题目描述这里有一幅服务器分布图,服务器的位置标识在 m * n ...
- TCP通信的客户端代码实现和TCP通信的服务器代码实现
TCP通信的客户端代码实现 package com.yang.Test.ServerStudy; import java.io.*; import java.net.Socket; /** * TCP ...
- [LeetCode] Count Binary Substrings 统计二进制子字符串
Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...
- [leetcode] 204. Count Primes 统计小于非负整数n的素数的个数
题目大意 https://leetcode.com/problems/count-primes/description/ 204. Count Primes Count the number of p ...
- [LeetCode] 164. Maximum Gap 求最大间距
Given an unsorted array, find the maximum difference between the successive elements in its sorted f ...
- LeetCode 164. Maximum Gap[翻译]
164. Maximum Gap 164. 最大间隔 Given an unsorted array, find the maximum difference between the successi ...
- Java实现 LeetCode 164 最大间距
164. 最大间距 给定一个无序的数组,找出数组在排序之后,相邻元素之间最大的差值. 如果数组元素个数小于 2,则返回 0. 示例 1: 输入: [3,6,9,1] 输出: 3 解释: 排序后的数组是 ...
- LeetCode双周赛#35
1589. 所有排列中的最大和 #差分 #贪心 题目链接 题意 给定整数数组nums,以及查询数组requests,其中requests[i] = [starti, endi] .第i个查询求 num ...
- LeetCode双周赛#34
5492. 分割字符串的方案数 #组合公式 #乘法原理 #区间分割 题目链接 题意 给定01二进制串\(s\),可将\(s\)分割为三个非空 字符串\(s_1,s_2,s_3\),即(\(s_1+s_ ...
随机推荐
- git注意事项
1,在github中新建空的工程,第一次提交代码的时候 使用命令 $ git push -u origin master -f 后面就直接push就行了
- RGBA的值0-255范围如何转换成0-1范围
这样一个rgba(1,0,0,1) 如果我们要把它转换成 0-255范围 就是rgb分别乘以255 就是 rgba(255,0,0,1) 0-255转0-1范围 如 rgba(34,56,56,1)转 ...
- typedef 复杂函数指针
下面是三个变量的声明,我想使用typedef分别给它们定义一个别名,请问该如何做? >1:int *(*a[5])(int, char*); >2:void (*b[10]) (void ...
- 【Shell】ps -ef 和ps aux
两者没太大差别 追溯到Unix系统中的两种风格,System V风格和BSD 风格,ps aux最初用到Unix Style中,而ps -ef被用在System V Style中,两者输出略有不同.现 ...
- Linux文件压缩、解压缩及归档工具一
主题Linux文件压缩.解压缩及归档工具 压缩工具很重要的,因为要经常到互联网下载包 一compress/uncompress compress [-dfvcVr] [-b maxbits] [fil ...
- 阿里云HBase推出普惠性高可用服务,独家支持用户的自建、混合云环境集群
HBase可以支持百TB数据规模.数百万QPS压力下的毫秒响应,适用于大数据背景下的风控和推荐等在线场景.阿里云HBase服务了多家金融.广告.媒体类业务中的风控和推荐,持续的在高可用.低延迟.低成本 ...
- Ververica Platform-阿里巴巴全新Flink企业版揭秘
摘要:2019云栖大会大数据 & AI专场,阿里巴巴资深技术专家王峰带来“Ververica Platform-阿里巴巴全新Flink企业版揭秘”的演讲.本文主要从Ververica由来开始谈 ...
- Struts2增删改查(自己思路理解)
1:查询所有: DAO层:把所有的信息都放到list集合中.然后返回. public List<Employee> getEmployees(){ return new ArrayList ...
- 洛谷 P2522 [HAOI2011]Problem b (莫比乌斯反演+简单容斥)
题目描述 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 输入输出格式 输入格式: 第一行一个整数 ...
- [CSP-S模拟测试72]题解
A.简单的序列 遇到括号匹配,先将左右括号转化为1和-1. 那么一个括号序列合法的必要条件:总和为0且所有时刻前缀和$\ge 0$. 用dp预处理出长度为$i$,总和为$j$的括号序列数量.那么如果p ...