leetcode

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

1221.cpp (372B)


      1 class Solution {
      2   public:
      3     int balancedStringSplit(const string &s) const {
      4         const int n = size(s);
      5         int res = 0;
      6 
      7         for (int i = 0; i < n; i++) {
      8             int count = s[i] == 'L' ? 1 : -1;
      9             while (count != 0) {
     10                 count += s[++i] == 'L' ? 1 : -1;
     11             }
     12             res++;
     13         }
     14 
     15         return res;
     16     }
     17 };