https://leetcode.com/problems/find-the-town-judge/
Find the Town Judge - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
class Solution {
public:
int findJudge(int n, vector<vector<int>>& trust) {
vector<bool> first_(n+1);
vector<int> second_(n+1);
int size = trust.size();
for (int i = 0; i < size; ++i) {
first_[trust[i][0]] = true;
++second_[trust[i][1]];
}
int ans = -1;
for (int i = 1; i <= n; ++i) {
if (first_[i]) continue;
if (second_[i] != n - 1) continue;
if (ans != -1) return -1;
ans = i;
}
return ans;
}
};
'알고리즘 > leetcode' 카테고리의 다른 글
Two Sum - easy (0) | 2021.08.02 |
---|---|
Making A Large Island (0) | 2021.08.01 |
Map Sum Pairs (0) | 2021.07.31 |
Partition Array into Disjoint Intervals (0) | 2021.07.22 |
Push Dominoes (0) | 2021.07.22 |