-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path199_BinarySearchRightView.cpp
58 lines (53 loc) · 1.05 KB
/
199_BinarySearchRightView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<string>
#include <set>
#include<vector>
#include<iostream>
#include<map>
#include<stack>
#include <unordered_set>
#include <algorithm> // std::min_element, std::max_element
using namespace std;
int findJudge(int N, vector<vector<int>>& trust) {
map<int, set<int>> mp;
int result = -1;
vector<int> couldNotBeJudge;
for (auto item : trust)
{
int key = item[1];
int value = item[0];
if (key != value )
{
//check if the value is already a key
set<int> s = mp[key];
s.insert(value);
mp[key] = s;
if (mp.find(value) != mp.end())
{
couldNotBeJudge.push_back(value);
}
}
else
{
couldNotBeJudge.push_back(value);
}
}
for (auto item : mp)
{
int size = item.second.size();
if (size == N - 1)
{
if (find(couldNotBeJudge.begin(), couldNotBeJudge.end(), item.first) == couldNotBeJudge.end())
result = item.first;
}
}
return result;
}
int main199()
{
//int count = climbStairs(5);
int N = 2;
vector<vector<int>> vec{ {1,2}, {2,1} };
int lnResult = findJudge(N, vec);
cout << lnResult;
return 0;
}