Leetcode-997 Find the Town Judge(?????????????????????)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode-997 Find the Town Judge(?????????????????????)相关的知识,希望对你有一定的参考价值。

?????????onclick   sof   ??????   rust   class   dba   mil   mic   back   

??????????????????????????????????????????????????????????????????????????????

???????????????????????????????????????N???1≤N≤1000????????????N?????????????????????1-N?????????"??????"??????????????????????????????????????????????????????????????????????????????vector???trust???????????????trust[i][0]??????????????????????????????trust[i][1]????????????????????????????????????????????????2??????????????????????????????(?????????????????????1)???0 ?????????(?????????????????????2)???N-1?????????????????????????????????????????????????????????1?????????????????????????????????????????????????????????????????????????????????????????????0?????????1????????????????????????????????????-1???

 

??????????????????

N = 4, trust = [[1,3],[1,4],[2,3],[2,4],[4,3]]

????????????????????????????????????????????????????????????????????????

????????????            ????????????

 

????????????
 1 #define pb push_back
 2 #define maxSize 3939
 3 #define _for(i,a,b) for(int i = (a);i < (b);i ++)
 4 
 5 class Solution
 6 {
 7     public:
 8         int findJudge(int N, vector<vector<int>>& trust)
 9         {
10             int hash[N+1][2];
11             memset(hash,0,sizeof(hash));
12             
13             int sz = trust.size();
14             _for(i,0,sz)
15             {
16                 hash[trust[i][0]][0] ++;
17                 hash[trust[i][1]][1] ++;
18             }
19             
20             int rnt = -1;
21             _for(i,1,N+1)
22             {
23                 if(hash[i][0]==0&&hash[i][1]==N-1)
24                 {
25                     if(rnt==-1)
26                         rnt = i;
27                     else
28                         return -1;
29                 }
30             }
31             return rnt;
32         }
33 };
Leetcode-997(C++)

????????????:364ms

以上是关于Leetcode-997 Find the Town Judge(?????????????????????)的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 997. Find the Town Judge

LeetCode --- 997. Find the Town Judge 解题报告

LeetCode --- 997. Find the Town Judge 解题报告

Leetcode-997 Find the Town Judge(?????????????????????)

LeetCode.997-找到镇法官(Find the Town Judge)

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