leetcode

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

0434.cpp (430B)


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