Skip to content

作业 #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Create 997_12
  • Loading branch information
hijkoo authored May 5, 2019
commit 8a2412242b05366c3a4413dd1fbb09b4df11fc8a
31 changes: 31 additions & 0 deletions Week_03/id_12/997_12
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Solution {

/**
* @param Integer $N
* @param Integer[][] $trust
* @return Integer
*/
function findJudge($N, $trust) {
if(count($trust)==1){
return $trust[0][1];
}
if(count($trust)==0){
return 1;
}

$countArr = [];
foreach($trust as $key=>$val){
$countArr[$val[0]] = -1;
if($countArr[$val[1]] !=-1){
$countArr[$val[1]]++;
}
}

for($i=0;$i<=$N;$i++){
if($countArr[$i] == $N-1){
return $i;
}
}
return -1;
}
}