997. 找到小镇的法官
为保证权益,题目请参考 997. 找到小镇的法官(From LeetCode).
解决方案1
CPP
C++
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution
{
public:
int findJudge(int N, vector<vector<int>> &trust)
{
int *dp_in = new int[N];
int *dp_out = new int[N];
fill(dp_in, dp_in+N,0);
fill(dp_out, dp_out+N,0);
for(int i=0;i<trust.size();++i)
{
dp_out[trust[i][0]-1]++;
dp_in[trust[i][1]-1]++;
}
for(int i=0;i<N;++i)
{
if(dp_out[i] == 0 && dp_in[i] == N-1)
{
return i+1;
}
}
return -1;
}
};
int mian()
{
return 0;
}
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
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