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)


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