leetcode

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

1419.cpp (537B)


      1 class Solution {
      2   public:
      3     int minNumberOfFrogs(const string &croakOfFrogs) const {
      4         static const string word = "croak";
      5         int count[5] = {0}, frogs = 0, res = 0;
      6 
      7         for (const char c : croakOfFrogs) {
      8             const int idx = word.find(c);
      9             if (idx == 0)
     10                 res = max(res, ++frogs);
     11             else if (!count[idx - 1]--)
     12                 return -1;
     13             else if (idx == 4)
     14                 frogs--;
     15             count[idx]++;
     16         }
     17 
     18         return !frogs ? res : -1;
     19     }
     20 };