Skip to content

Commit

Permalink
Create find-the-judge.cpp
Browse files Browse the repository at this point in the history
doing some in C++
  • Loading branch information
gabedonnan authored Jan 23, 2023
1 parent f358f9f commit 3f2c641
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions find-the-judge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution {
public:
int findJudge(int n, vector<vector<int>>& trust) {
std::vector<int> trusters;
std::vector<int> trustees;
for (const std::vector<int>& h: trust) {
//std::cout << h[0] << std::endl << h[1] << std::endl;
trusters.push_back(h[0]);
trustees.push_back(h[1]);
}

for (int i = 1; i <= n; i++) {
//std::cout << i << "\n";
if (std::count(trusters.begin(), trusters.end(), i)){
continue;
} else {
//std::cout << trustees[i-1] << "TRUSTEE" << "\n";
if (std::count(trustees.begin(), trustees.end(), i) == n-1){
return i;
}
}
}
return -1;
}
};

0 comments on commit 3f2c641

Please sign in to comment.