leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2374.cpp (512B)


      1 class Solution {
      2   public:
      3     int edgeScore(vector<int> &edges) {
      4         vector<long long> score(edges.size(), 0);
      5         long long maxi = LONG_MIN;
      6         int index = -1;
      7 
      8         for (int i = 0; i < edges.size(); i++) {
      9             score[edges[i]] += i;
     10             if (score[edges[i]] > maxi) {
     11                 maxi = score[edges[i]];
     12                 index = edges[i];
     13             } else if (score[edges[i]] == maxi)
     14                 index = min(index, edges[i]);
     15         }
     16 
     17         return index;
     18     }
     19 };