题目描述:

自己的提交:

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. docker-ce创建gitlab-ce容器笔记

    前言 vagrant + ubuntu 16.04 设置 apt 源 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak sudo vim ...

  2. webpack 学习4 使用loader 以及常用的一些loader

    webpack本身只支持处理JavaScript,其他的文件,如css img less是不识别的,所以才会有loader这个东西,它就是可以使webpack能够处理其他非js文件的拓展程序 首先我们 ...

  3. function的各做写法

    function(){}()让变量快速初始化结果 var timestamp = function(){ var timestamp = Date.parse(new Date()); return ...

  4. 使用conda部署jupyterhub以及ladp验证的安装

    前提:机器安装有conda环境 官方文档:http://jupyterhub.readthedocs.io/en/stable/quickstart.html 1.安装conda3 jupyterhu ...

  5. shell 中| 用法

    | 运算符 管道符号,是unix一个很强大的功能,符号为一条竖线:"|".用法: command 1 | command 2 他的功能是把第一个命令command 1执行的结果作为 ...

  6. org.zkoss.zul.Filedownload.java 源码

    /* Filedownload.java Purpose: Description: History: Mon Apr 16 09:29:44 2007, Created by tomyeh Copy ...

  7. 【LeetCode 38】报数

    题目链接 [题解] 模拟题 [代码] class Solution { public: string inttostr(int x){ string temp=""; while ...

  8. Android 模糊搜索rawquery bind or column index out of range: handle 0x2fb180 报错

    做模糊搜索时,出现了  bind or column index out of range: handle 0x2fb180 报错 public Cursor getTitle(String word ...

  9. ShopNC B2B2C最新版去除shop方法教程

    1.转移shop下目录文件至根目录: 2.修改config.ini.php里的shop绑定域名更改为无shop目录: 3.将原始根目录的index.php更改为main.php文件名自己定!并修改in ...

  10. kvm无人值守安装centos 7虚拟机

    centos 7安装好KVM之后还要安装虚拟机,通过VNC连接手动安装centos 7虚拟机太麻烦了,所以无人值守安装是做好的.简单记录下. 无人值守安装centos 7前提是要安装KVM,并且能手动 ...