From 3f2c64136a8a67511c04e1c96ed687aa591298e4 Mon Sep 17 00:00:00 2001 From: Gabriel Donnan <47415809+gabedonnan@users.noreply.github.com> Date: Mon, 23 Jan 2023 12:03:08 +0000 Subject: [PATCH] Create find-the-judge.cpp doing some in C++ --- find-the-judge.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 find-the-judge.cpp diff --git a/find-the-judge.cpp b/find-the-judge.cpp new file mode 100644 index 0000000..134e6cf --- /dev/null +++ b/find-the-judge.cpp @@ -0,0 +1,25 @@ +class Solution { +public: + int findJudge(int n, vector>& trust) { + std::vector trusters; + std::vector trustees; + for (const std::vector& 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; + } +};