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_ ...
随机推荐
- mongodb与java的整合
mongodb的相关命令我们这里不在赘述,因为其文档下写的非常清楚,也很容易懂.这里我们说一下其余java的整合,mongodb配置请查看官方文档 1.首先我们应该导入期相关依赖, org.mongo ...
- JavaSE---Object
1.概述 Object常用方法: 1.1 getClass(): public final native Class<?> getClass(); 返回 该对象 运行时的Class ...
- 【leetcode】756. Pyramid Transition Matrix
题目如下: We are stacking blocks to form a pyramid. Each block has a color which is a one letter string, ...
- Security Spring 配置
<?xml version="1.0" encoding="UTF-8"?><beans:beans xmlns="http://w ...
- 开放融合 | “引擎级”深度对接!POLARDB与SuperMap联合构建首个云原生时空平台
阿里巴巴新一代自研云数据库POLARDB与超图软件SuperMap GIS实现 “引擎级”深度对接,构建了自治.弹性.高可用的云原生时空数据管理平台联合解决方案,推出了业界首个“云原生数据库+云原生G ...
- php abs()函数 语法
php abs()函数 语法 abs()函数怎么用? abs()函数的作用是返回一个数的绝对值.语法是abs(number),如果参数 number 是 float,则返回的类型也是 float,否则 ...
- centos7 安装PHP5.3 报错undefined reference to symbol '__gxx_personality_v0@@CXXABI_1.3'
系统:centos 7 原有PHP版本:5.6.27,5.4.45 试着安装nginx+多php版本,首先安装了5.6和5.4的版本,一帆风顺,但是在安装5.3.29版本时,出现问题了,configu ...
- 分布式系统理论基础1: 一致性、2PC和3PC
本文转自 https://www.cnblogs.com/bangerlee/p/5268485.html 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到 ...
- Windows下 wamp下Apache配置虚拟域名
安装好wamp后 找到 找到 Include conf/extra/httpd-vhosts.conf 去掉前面的# 并保存 修改 DocumentRoot 和 ServerName ...
- 如何理解c和c++的复杂类型声明
曾经碰到过让你迷惑不解.类似于int * (* (*fp1) (int) ) [10];这样的变量声明吗?本文将由易到难,一步一步教会你如何理解这种复杂的C/C++声明. 我们将从每天都能碰到的较简单 ...