Skip to content

Comments

Completed Graph-1#786

Open
Nikesh46 wants to merge 1 commit intosuper30admin:masterfrom
Nikesh46:master
Open

Completed Graph-1#786
Nikesh46 wants to merge 1 commit intosuper30admin:masterfrom
Nikesh46:master

Conversation

@Nikesh46
Copy link

No description provided.

@super30admin
Copy link
Owner

Your solution for the "Find the town Judge" problem is correct and efficient. Well done! Here are a few suggestions for improvement:

  1. Consider using an array instead of a HashMap for the trust counts. Since the people are labeled from 1 to n, an array of size n+1 would be more efficient in terms of constant factors and might be simpler.
  2. The variable name 't' in the for-loop could be changed to something more descriptive, like 'trustRelation' or 'edge', to enhance readability.
  3. You have included a check for n==1 at the beginning, which is good. However, note that if there are no trust relationships and n>1, the judge cannot exist. Your solution handles this correctly because the HashMap might not have an entry for every person, so the loop checks only keys that exist. But using an array initialized to zeros would also work and might be more straightforward.

Overall, your solution is excellent. Keep up the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants