leetcode

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

0893.cpp (536B)


      1 class Solution {
      2   public:
      3     int numSpecialEquivGroups(const vector<string> &words) {
      4         unordered_set<string> st;
      5         const int n = words[0].size();
      6         for (const auto &word : words) {
      7             string s1, s2;
      8             for (int i = 0; i < n; i += 2)
      9                 s1 += word[i];
     10             for (int i = 1; i < n; i += 2)
     11                 s2 += word[i];
     12             sort(begin(s1), end(s1));
     13             sort(begin(s2), end(s2));
     14             st.insert(s1 + ' ' + s2);
     15         }
     16         return st.size();
     17     }
     18 };