leetcode

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

2038.cpp (567B)


      1 class Solution {
      2   public:
      3     bool winnerOfGame(const string &colors) {
      4         int a = 0, b = 0, i = 0;
      5         while (i < colors.size()) {
      6             int count = 0;
      7             if (colors[i] == 'A') {
      8                 while (i < colors.size() && colors[i] == 'A')
      9                     i++, count++;
     10                 if (count > 2) a += count - 2;
     11             } else {
     12                 while (i < colors.size() && colors[i] == 'B')
     13                     i++, count++;
     14                 if (count > 2) b += count - 2;
     15             }
     16         }
     17         return a > b;
     18     }
     19 };