LeetCode #997. Find the Town Judge

LeetCode --- 997. Find the Town Judge 解题报告 In a town, there arenpeople labeled from1ton. There is a rumor that one of these people is secretly the town judge. If the town judge exists, then: The town judge trusts nobody. Everybody (except for the town judge) trusts the town judge. There is... 阅读详情

题目描述:

In a town, there are N people labelled from 1 to N.  There is a rumor that one of these people is secretly the town judge.

If the town judge exists, then:

  1. The town judge trusts nobody.
  2. Everybody (except for the town judge) trusts the town judge.
  3. There is exactly one person that satisfies properties 1 and 2.

You are given trust, an array of pairs trust[i] = [a, b] representing that the person labelled a trusts the person labelled b.

If the town judge exists and can be identified, return the label of the town judge.  Otherwise, return -1.

Example 1:

Input: N = 2, trust = [[1,2]]
Output: 2

Example 2:

Input: N = 3, trust = [[1,3],[2,3]]
Output: 3

Example 3:

Input: N = 3, trust = [[1,3],[2,3],[3,1]]
Output: -1

Example 4:

Input: N = 3, trust = [[1,2],[2,3]]
Output: -1

Example 5:

Input: N = 4, trust = [[1,3],[1,4],[2,3],[2,4],[4,3]]
Output: 3

Note:

  1. 1 <= N <= 1000
  2. trust.length <= 10000
  3. trust[i] are all different
  4. trust[i][0] != trust[i][1]
  5. 1 <= trust[i][0], trust[i][1] <= N
class Solution {
public:
    int findJudge(int N, vector<vector<int>>& trust) {
        vector<int> a(N+1,0), b(N+1,0);
        for(auto x:trust)
        {
            a[x[0]]++;
            b[x[1]]++;
        }
        for(int i=1;i<=N;i++)
        {
            if(a[i]==0&&b[i]==N-1) return i;
        }
        return -1;
    }
};

 

afsim源码编译生成出现错误解决方法 不同版本Cmake可能会导致编译出现问题,针对afsim 2.9版本,如果使用3.30版本的出现问题,建议卸载后重新安装3.27.1版本的cmake。这里存在两种原因,一种是Cmake版本问题,另外一种是软件之间存在冲突。上面这张图有警告是没有问题的,不影响,可以忽略。中的路径下找,因此,出现这个情况的原因是把。如果是经常使用 python 环境,例如。软件安装目录加入到windows的。在Visual Studio中对。和其它软件存在冲突的情况。中,导致搜索出现问题。软件的安装目录下也有。 阅读详情

相关推荐

在STM32上运行小波变换及神经网络算法——(一)单片机中小波算法编写

在单片机上实现离散小波变换的C代码,通过确定信号长度、小波分解层数、小波基名称后进行编写,并改写成了方便调用的结构体格式。

weixin_45400202的博客 1000

【LeetCode】【C++】997. 找到小镇的法官

LeetCode 997. 找到小镇的法官

YGGP的博客 1065

流媒体协议-RTMP简介

与rtsp 不同,RTSP(Real-Time Streaming Protocol)是一个控制协议,负责控制媒体流的传输,但不传输媒体数据本身。RTSP 可以通过 TCP 或 UDP 传输 RTP 包来传输音视频数据。 RTMP(Real-Time Messaging Protocol)是一个综合性的协议,不仅可以传输音视频数据,还可以传输信令控制指令。RTMP 使用 TCP 作为传输协议,可以直接在 TCP 连接上传输音视频数据,也可以传输控制指令,实现了音视频流的实时传输和控制

xiaoshuaijinniu的博客 4568

《中英双解》leetCode Find the town judge(找到小镇法官)

In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge. If the town judge exists, then: The town judge trusts nobody. Everybody (except for the town judge) trusts the town judge. There is .

weixin_46272350的博客 303

Ubuntu 20.04 环境下Autoware.universe 与 Carla 0.9.13 联合仿真

安装内容: ROS Galactic Autoware.universe based on ROS Galactic Carla 0.9.13 UnrealEngine 4.26 Openplanner (additional files: op-bridge/op-agent/scenariorunner/map data)

mhl1107的博客 1807

MT6768平台Sensor Bring Up全流程实战:从驱动添加到问题排查(附避坑指南)

本文详细介绍了联发科MT6768平台Sensor Bring Up的全流程实战指南,从驱动添加、硬件配置到问题排查,提供了全面的避坑建议。内容涵盖环境准备、驱动文件集成、硬件接口配置、编译系统适配以及常见问题解决方案,帮助开发者高效完成传感器集成与调试工作。

weixin_30374009的博客 425

5月挑战Day10-Find the Town Judge(easy)

Day10-Find the Town Judge 问题描述: In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge. If the town judge exists, then: The town judge trusts nobody. Everybody (except for the town judge) t

A*J的博客 201

Ta-Lib源码解析(三):蜡烛图指标 (Candlestick Indicator) #(附Python重构代码和示意图)(补充中)

蜡烛图指标为识别K线形态的指标,笔者认为重点在于定义方式所提供的思路,背后的投资逻辑可以借鉴但不建议直接参考文档的翻译内容和源码逻辑存在不一致的现象,笔者分别列出中文百科中的定义和源码实际逻辑,供大家参考技术分析理论中的一些模糊词,ta-lib中给出了精确的定义源码

量化就是探索生活 3291

图论——找到小镇的法官

一、问题描述 小镇里有 n 个人,按从 1 到 n 的顺序编号。传言称,这些人中有一个暗地里是小镇法官。 如果小镇法官真的存在,那么: 小镇法官不会信任任何人。 每个人(除了小镇法官)都信任这位小镇法官。 只有一个人同时满足属性 1 和属性 2 。 给你一个数组 trust ,其中 trust[i] = [ai, bi] 表示编号为 ai 的人信任编号为 bi 的人。 如果小镇法官存在并且可以确定他的身份,请返回该法官的编号;否则,返回 -1 。 二、C语言代码 int findJudge(int n,

si_ying的博客 1842

DataCastle-租金预测

ID:编号;时间:房屋信息采集的时间;小区名:房屋所在小区,已脱敏处理;小区房屋出租数量:小区出租房屋数量,已脱敏处理;楼层:0、1、2分别表示楼层低,中,高;总层数:房屋所在建筑的总楼层数,已脱敏处理;房屋面积:房屋面积数值,已脱敏处理;房屋朝向:房屋的朝向;居住状态:房屋的居住状态,表示是否已出租或居住中,已脱敏处理;卧室数量:户型信息,数字表示卧室的个数;卫的数量:户型信息,数字表示卫生间的个数;厅的数量:户型信息,数字表示厅的个数;

CSDN 精品推荐 3470

SAP-ABAP:SAP数据库视图的创建图文详解

在“短文本”字段中输入视图的描述。在“表/视图”字段中输入要基于的表名。如果视图基于多个表,可以在这里输入主表。点击“表/视图字段”按钮,选择要包含在视图中的字段。如果视图基于多个表,点击“关系”按钮来定义表之间的连接条件。在弹出的窗口中,选择要连接的表,并定义连接条件(例如。

baidu_35680696的博客 980

[Leetcode学习-java]Find the Town Judge(找镇上法官)

问题: 难度:easy 原文: In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge. If the town judge exists, then: The town judge trusts nobody. Everybody (except for the town judge) trusts the

qq_28033719的博客 212

【Go语言实战】(9) gRPC 实现一个简单微服务

文章目录写在前面1. 安装1.1 grpc1.2 proto1.3 protobuf2. 编写代码2.1 初始化项目2.2 编写proto2.3 编写服务端2.4 实现客户端3. 演示 写在前面 这一次我们用gRPC实现获取用户的信息 1. 安装 1.1 grpc grpc的安装直接go get即可 go get google.golang.org/grpc 1.2 proto 下载proto,我是下载这个的。 然后解压出来把bin目录放在直接放在系统变量当中 1.3 protobuf 我们在

面向生活编程 3276

[leetcode] 997. Find the Town Judge @ python

原题 In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge. If the town judge exists, then: The town judge trusts nobody. Everybody (e...

闲庭信步 927

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Leetcode997. Find the Town Judge

【代码】Leetcode997. Find the Town Judge。

weixin_50796535的博客 501

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

LeetCode 997. Find the Town Judge

LeetCode 997 这个法官不能信任任何人,所有如果我们有这个N个人的集合,可以把任何有信任关系的人排除。 然后在candidate中找到所有人都信任他的人。 candidates = set(i for i in range(1, N+1)) trustdict = collections.defaultdict(set) for tk in trust: a = tk[0] b = tk[1]

frankguodongchen的博客 185

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

#力扣 LeetCode997. 找到小镇的法官 @FDDLC

题目描述: https://leetcode-cn.com/problems/find-the-town-judge/ 自测用例: 2 [[1,2]] 3 [[1,3],[2,3]] 3 [[1,3],[2,3],[3,1]] 3 [[1,2],[2,3]] 4 [[1,3],[1,4],[2,3],[2,4],[4,3]] 1 []

LiuXingchang的博客 252

9.2.2 图的遍历LeetCode题目 —— Find the Town Judge & Clone Graph & Keys and Rooms

133.Clone Graph Given a reference of a node in aconnectedundirected graph. Return adeep copy(clone) of the graph. Each node in the graph contains a val (int) and a list (List[Node]) of its neighbors. 题解: 注意题目的入参和出参,都是Node结构,而题目说明及例子多少绕了个弯。 ...

xutiantian1412的博客 368

LeetCode刷题碎碎念(四):Graph

LeetCode刷题碎碎念(四):GraphGraphqueue + hashtable Graph queue + hashtable

Hanhahahahah的博客 1286

每日一题之图论

在一个小镇里,按从 1 到 n 为 n 个人进行编号。传言称,这些人中有一个是小镇上的秘密法官。 如果小镇的法官真的存在,那么: 小镇的法官不相信任何人。 每个人(除了小镇法官外)都信任小镇的法官。 只有一个人同时满足条件 1 和条件 2 。 给定数组trust,该数组由信任对 trust[i] = [a, b]组成,表示编号为 a 的人信任编号为 b 的人。 如果小镇存在秘密法官并且可以确定他的身份,请返回该法官的编号。否则,返回 -1。 示例 1: 输入:n = 2, trust = ..

m0_50290125的博客 491

LeetCode - 997 -找到小镇的法官 - Java

文章目录题目及要求题目解析代码实现第一步:创建一个 容量为 n +1 的一维数组(如果没有:这句按照从1到n对n个人进行编号,我就直接new int[n] 了)计票(遍历题目所给的二维数组来统计票数)通过 遍历 我们 的 计票数组 poll ,来看看有没有一个人获取所有的票。最后附上代码 题目及要求   题目解析 先来分析 第一句话:“在一个小镇里,按从 1 到 n 为 n 个人进行编号。传言称,这些人中有一个是小镇上的秘密法官。” 注意到 我 加粗的字体了嘛?这些就是这句话关键点之一 ! 在加上这

DarkAndGrey的博客 963

997. Find the Town Judge

997. 找到小镇的法官 在一个小镇里,按从 1 到 N 标记了N 个人。传言称,这些人中有一个是小镇上的秘密法官。 如果小镇的法官真的存在,那么: 小镇的法官不相信任何人。 每个人(除了小镇法官外)都信任小镇的法官。 只有一个人同时满足属性 1 和属性 2 。 给定数组trust,该数组由信任对 trust[i] = [a, b]组成,表示标记为 a 的人信任标记为 b 的人。...

GGGGITFKBJG的主页 192

Leetcode 997:找到小镇的法官(超详细的解法!!!)

在一个小镇里,按从 1 到 N 标记了 N 个人。传言称,这些人中有一个是小镇上的秘密法官。 如果小镇的法官真的存在,那么: 小镇的法官不相信任何人。 每个人(除了小镇法官外)都信任小镇的法官。 只有一个人同时满足属性 1 和属性 2 。 给定数组 trust,该数组由信任对 trust[i] = [a, b] 组成,表示标记为 a 的人信任标记为 b 的人。 如果小镇存在秘密法官并且可以确定...

coordinate的博客 3263

LeetCode第 997 题:找到镇上的法官(C++)

997. 找到小镇的法官 - 力扣(LeetCode) 一开始的做法是这样的: class Solution { public: int findJudge(int N, vector<vector<int>>& trust) { vector<int> sign(N+1, 0);//i有信任的人,则sign[i] = 1 vector<int> count(N+1, 0);//信任i的人的个数是count[i]

zj 400

Leetcode 997. Find the Town Judge

In a town, there are N people labelled from 1 to N.  There is a rumor that one of these people is secretly the town judge. If the town judge exists, then: The town judge trusts nobody. Everybody (...

Dive Deep into The Knowledge 562

LeetCode997.Find the Town Judge(找到小镇的法官)

997.Find the Town Judge(找到小镇的法官)DescriptionDifficulty: easyExample 1:Example 2:Example 3:Example 4:Example 5:Note:分析参考代码 Description In a town, there are N people labelled from 1 to N. There is a rum...

redtongue的博客 810
上一篇: LeetCode #1099. Two Sum Less Than K
下一篇: LeetCode #1022. Sum of Root To Leaf Binary Numbers
LawFile
博客等级 码龄10年 5粉丝 627原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址