diff --git "a/2101040022/chapter_8/\346\211\276\345\210\260\345\260\217\351\225\207\347\232\204\346\263\225\345\256\230.cpp" "b/2101040022/chapter_8/\346\211\276\345\210\260\345\260\217\351\225\207\347\232\204\346\263\225\345\256\230.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..e3a210db3ce24949acdd544e75908ebad695a382 --- /dev/null +++ "b/2101040022/chapter_8/\346\211\276\345\210\260\345\260\217\351\225\207\347\232\204\346\263\225\345\256\230.cpp" @@ -0,0 +1,22 @@ +class Solution { +private: + int arr[1001]; + int brr[1001]; +public: + int findJudge(int n, vector>& trust) { + for (int i = 0; i < trust.size(); i++) { + arr[trust[i][0]]++; + brr[trust[i][1]]++; + } + int cnt = 0; + int index = 0; + for (int i = 1; i <= n; i++) { + if (arr[i] == 0 && brr[i] == n - 1) { + cnt++; + index = i; + } + } + if (cnt == 1) { return index; } + else { return -1; } + } +}; \ No newline at end of file