leetcode

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

2053.cpp (331B)


      1 class Solution {
      2   public:
      3     string kthDistinct(const vector<string> &arr, int k) const {
      4         unordered_map<string, int> um;
      5 
      6         for (const auto &s : arr)
      7             um[s]++;
      8         for (const auto &s : arr) {
      9             if (um[s] > 1) continue;
     10             if (!--k) return s;
     11         }
     12 
     13         return "";
     14     }
     15 };