题目描述:

自己的提交:

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. 一次goldengate故障引发的操作系统hang起,HA自动切换

    现场: 跑着数据库的主机A报警应用连接不上数据库,我们无法ssh到主机.第一反应是通过telnet到远程控制口,发现数据库资源和硬件资源在被切换到HA架构的主机B(备机,通常性能比主机A的差,抗不住应 ...

  2. Vue学习笔记【30】——Vue路由(watch属性的使用)

    考虑一个问题:想要实现 名 和 姓 两个文本框的内容改变,则全名的文本框中的值也跟着改变:(用以前的知识如何实现???) 监听data中属性的改变:  <div id="app&quo ...

  3. Centos MySQL 5.7安装、升级教程

    MySQL 5.7安装.升级笔记分享: 卸载当前的 MySQL 查看当前 MySQL 版本: ? 1 2 [root@coderknock ~]# mysql -V mysql Ver 14.14 D ...

  4. Anaconda 安装 pytorch报错解决方法

    一.安装Pytorch: # -c 指定用pytorch镜像源下载软件conda install pytorch torchvision cpuonly -c pytorch 报错: 二.配置: ch ...

  5. vue基础六

    列表渲染 1.v-for 我们用 v-for 指令根据一组数组的选项列表进行渲染. v-for 指令需要以 item in items 形式的特殊语法(也可以用of代替in), items是源数据数组 ...

  6. 【Flutter学习】基本组件之TabBar顶部导航

    一,概述 TabBar,是材料设计(Material design)中很常用的一种横向标签页.在Android原生开发中,我们常用ViewPage或者一些常用的标签页开源库,来实现并行界面的横向滑动展 ...

  7. Python基础教程(008)--第一个Python程序

    前言: 学会第一个Python程序 了解Python2和Python3的区别 内容 执行Python程序的三种方式 解释器--Python.Python3 交互式-- ipthon 集成开发环境--P ...

  8. poi提取docx中的文字和图片

    package com.fry.poiDemo.dao; import java.io.File; import java.io.FileInputStream; import java.io.Fil ...

  9. PAT甲级——A1144 TheMissingNumber【20】

    Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...

  10. Python django tests

    单元测试函数必须以test_开头,否则无法被识别