leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1419.cpp (537B)
0 class Solution {
1 public:
2 int minNumberOfFrogs(const string &croakOfFrogs) const {
3 static const string word = "croak";
4 int count[5] = {0}, frogs = 0, res = 0;
6 for (const char c : croakOfFrogs) {
7 const int idx = word.find(c);
8 if (idx == 0)
9 res = max(res, ++frogs);
10 else if (!count[idx - 1]--)
11 return -1;
12 else if (idx == 4)
13 frogs--;
14 count[idx]++;
15 }
17 return !frogs ? res : -1;
18 }
19 };