LeetCode题解之 Find the Town Judge
1、题目描述

2、问题分析
使用map set数据结构。
3、代码
int findJudge(int N, vector<vector<int>>& trust) {
if (trust.size() == )
return ;
int n = ;
map<int, int> m;
set<int> s;
for (auto it = trust.begin(); it != trust.end(); it++) {
m[(*it).back()]++;
s.insert((*it).front());
}
int peo = INT_MIN;
for (auto it = m.begin(); it != m.end(); it++) {
if (it->second > n){
n = it->second;
peo = it->first;
}
}
return ((n == (N - )) && s.find(peo) == s.end()) ? peo : -;
}
LeetCode题解之 Find the Town Judge的更多相关文章
- 【LeetCode】997. Find the Town Judge 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 度 日期 题目地址:https://leetcode ...
- 【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 ...
- #Leetcode# 997. Find the Town Judge
https://leetcode.com/problems/find-the-town-judge/ In a town, there are N people labelled from 1 to ...
- [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 ...
- 【LeetCode题解】二叉树的遍历
我准备开始一个新系列[LeetCode题解],用来记录刷LeetCode题,顺便复习一下数据结构与算法. 1. 二叉树 二叉树(binary tree)是一种极为普遍的数据结构,树的每一个节点最多只有 ...
- leetcode题解-122买卖股票的最佳时期
题目 leetcode题解-122.买卖股票的最佳时机:https://www.yanbinghu.com/2019/03/14/30893.html 题目详情 给定一个数组,它的第 i 个元素是一支 ...
- 【LeetCode题解】3_无重复字符的最长子串(Longest-Substring-Without-Repeating-Characters)
目录 描述 解法一:暴力枚举法(Time Limit Exceeded) 思路 Java 实现 Python 实现 复杂度分析 解法二:滑动窗口(双指针) 思路 Java 实现 Python 实现 复 ...
- 【LeetCode题解】225_用队列实现栈(Implement-Stack-using-Queues)
目录 描述 解法一:双队列,入快出慢 思路 入栈(push) 出栈(pop) 查看栈顶元素(peek) 是否为空(empty) Java 实现 Python 实现 解法二:双队列,入慢出快 思路 入栈 ...
- 【LeetCode题解】232_用栈实现队列(Implement-Queue-using-Stacks)
目录 描述 解法一:在一个栈中维持所有元素的出队顺序 思路 入队(push) 出队(pop) 查看队首(peek) 是否为空(empty) Java 实现 Python 实现 解法二:一个栈入,一个栈 ...
随机推荐
- Jenkins问题记录:android构建时提示Unzipping /home/.gradle/wrapper/dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9/gradle-3.3-all.zip to /home/.gradle/wrapper/dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9 Except
-------------- -------------- 问题:今日job构建报出如下错误: Unzipping /home/.gradle/wrapper/dists/gradle-3.3-all ...
- xcodebuild构建时报错unknown error -1=ffffffffffffffff Command /bin/sh failed with exit code 1
CI今日构建时报出如下错误: /Users/xxx/Library/Developer/Xcode/DerivedData/Snowball-ebllohyukujrncbaldsfojfjxwep/ ...
- Java 锁优化
一.重量级锁 Java中,Synchronized是通过对象内部的一个叫做监视器锁(monitor)来实现的.但是监视器锁本质又是依赖于底层的操作系统的Mutex Lock来实现的.而操作系统实现 ...
- 不规范的json文档 转化成 java 对象的处理
最近练习爬取数据,遇到了json文档中属性名称没有用双引号的情况,内容如下: 标准的json文档,属性名称都是带双引号的 最后写了个方法,替换属性名字 为 两头追加双引号的属性名字, 特别要注意,防止 ...
- 设计shell脚本选项:getopt
man 1 getopt翻译:https://www.cnblogs.com/f-ck-need-u/p/9757959.html 写shell脚本的时候,通过while.case.shift来设计脚 ...
- mybatis的延迟加载、一级缓存、二级缓存
mybatis的延迟加载.一级缓存.二级缓存 mybatis是什么? mybatis是一个持久层框架,是apache下的开源项目,前身是itbatis,是一个不完全的ORM框架,mybatis提供输入 ...
- RNN入门(二)识别验证码
介绍 作为RNN的第二个demo,笔者将会介绍RNN模型在识别验证码方面的应用. 我们的验证码及样本数据集来自于博客: CNN大战验证码,在这篇博客中,我们已经准备好了所需的样本数据集,不需要 ...
- [转]VS2015 Cordova Ionic移动开发(一)
本文转自:https://www.cnblogs.com/UltimateAvalon/p/5328642.html 一.Windows环境配置 1.如果已经安装VS2015,打开[工具]-[选项]找 ...
- Spring Bean的生命周期相关博客
最近得面试题一直 问 Spring 得生命周期,鉴于自己还未阅读过源码 所以只能是自己 背一波了.属实不懂硬背得作用,但是无奈被各位面试官打败了.等以后有时间了 一定要阅读几遍spring的 源码 有 ...
- 【Java每日一题】20170224
20170223问题解析请点击今日问题下方的“[Java每日一题]20170224”查看(问题解析在公众号首发,公众号ID:weknow619) package Feb2017; import jav ...