leetcode

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

0860.cpp (752B)


      1 class Solution {
      2   public:
      3     bool lemonadeChange(const vector<int> &bills) const {
      4         int count[2] = {0, 0};
      5 
      6         for (const int n : bills) {
      7             switch (n) {
      8             case 5: count[0]++; break;
      9             case 10:
     10                 if (count[0] == 0) return false;
     11                 count[0]--;
     12                 count[1]++;
     13                 break;
     14             case 20:
     15                 if (count[0] > 0 && count[1] > 0) {
     16                     count[0]--;
     17                     count[1]--;
     18                     break;
     19                 }
     20 
     21                 if (count[0] >= 3) {
     22                     count[0] -= 3;
     23                     break;
     24                 }
     25 
     26                 return false;
     27             }
     28         }
     29 
     30         return true;
     31     }
     32 };