We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
997. 找到小镇的法官
function findJudge(n: number, trust: number[][]): number { // 寻找图中出度为 0 的节点 // key:被信任的人,value:被多少人信任 let peopleWhoBeTrustedMap = new Map(); // 信任别人的人 let peopleWhoTrustOther = new Set(); trust.forEach(item => { peopleWhoBeTrustedMap.set(item[1], (peopleWhoBeTrustedMap.get(item[1]) || 0) + 1) peopleWhoTrustOther.add(item[0]) }) let res = -1; //法官 for (let i = 1; i <= n; i++) { // !peopleWhoTrustOther.has(i) 法官不信任其他人 // (peopleWhoBeTrustedMap.get(i) || 0) === n - 1 其他人都信任法官 if (!peopleWhoTrustOther.has(i) && (peopleWhoBeTrustedMap.get(i) || 0) === n - 1) { res = i; } } return res; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
997. 找到小镇的法官
The text was updated successfully, but these errors were encountered: