leetcode997
class Solution:
def findJudge(self, N: int, trust: 'List[List[int]]') -> int:
if N==1 and len(trust)==0:
return 1
s = list(range(1,N+1))
d = {}
for t in range(len(trust)):
a1 = trust[t][0]
a2 = trust[t][1]
if a1 in s:
s.remove(a1)
if a2 in d.keys():
d.update({a2:d[a2]+1})
else:
d.update({a2:1})
if len(s)==1 and s[0] in d.keys() and d[s[0]]==N-1:
return s[0]
else:
return -1
leetcode997的更多相关文章
- [Swift]LeetCode997. 找到小镇的法官 | 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 se ...
- LeetCode997. Find the Town Judge
题目 在一个小镇里,按从 1 到 N 标记了 N 个人.传言称,这些人中有一个是小镇上的秘密法官. 如果小镇的法官真的存在,那么: 小镇的法官不相信任何人. 每个人(除了小镇法官外)都信任小镇的法官. ...
随机推荐
- java中构造方法和普通方法的区别
1.普通方法: 定义:简单的说方法就是完成特定功能的代码块. 普通方法定义格式: 修饰符 返回值类型 方法名 (参数类型 参数名1,参数类型 参数名2,.........) { 函数体: re ...
- Python利用Plotly实现对MySQL中的数据可视化
Mysql表数据: demo.sql内容 create table demo( id int ,product varchar(50) ,price decimal(18,2) ,quantity i ...
- IIS性能优化篇
首先程序的优化,不只是沿着一个点进行,往往都是程序配合服务器及数据服务器配置提升性能. 第一步:数据库链接优化 在数据库链接字符串中添加“Max Pool Size=32767;”,32767是数据库 ...
- python selenium 模拟登陆百度账号
代码: from selenium import webdriver url = 'https://passport.baidu.com/v2/?login' username = 'your_use ...
- ROS-MikroTik-RouterOS-培训认证各种证书
官方原文: https://mikrotik.com/training/about MikroTik certified training programs MTCNA - MikroTik Cert ...
- 以太网安全技术ACL原理+配置
一.以太网访问控制列表 主要作用:在整个网络中分布实施接入安全性 访问控制列表ACL(Access Control List)为网络设备提供了基本的服务安全性.对某个服务而言,安全管理员首先应该考虑的 ...
- [UE4]位移和形变 Render Transform
任何UI控件都有Render Transform属性. 一.Transform,对应游戏场景中的Transform 1.Translation:位置,平移.对应游戏场景的Transform中的Lo ...
- ipv6 操作
netsh interface teredo set state disablednetsh interface ipv6 add v6v4tunnel interface=IP6Tunnel 120 ...
- Echarts动态加载饼状图的实例
一.引入echarts.js文件(下载页:http://echarts.baidu.com/download.html) 二.HTML代码: <div style="width: 10 ...
- JAVA List合并集合
import java.util.ArrayList; import java.util.List; public class test { public static void main(Strin ...