[C++/Python] linear scanning with two pointers
C++\n\n\nclass Solution {// Linear scanning with two pointers\npublic: // Time/Space: O(N); O(1)\n    int maxPower(string s) {\n        int ans = 1;\n        fo
C++\n\n```\nclass Solution {// Linear scanning with two pointers\npublic: // Time/Space: O(N); O(1)\n    int maxPower(string s) {\n        int ans = 1;\n        for(int i = 1, prev = 0, n = s.size(); i < n; i++){\n            while(i < n && s[i] == s[prev]) i++;\n            ans = max(ans, i - prev);\n            prev = i;\n        }\n        return ans;\n    }\n};\n```\n\nPython: \n```\ndef maxPower(self, s):\n        return max(len(list(b)) for a, b in itertools.groupby(s))\n```\nNotes: playing with itertools.groupby:\n\n```\ns = "leetcode"\nfor a, b in itertools.groupby(s):print(a, " --> ", b, " --> ", list(b))\n```\nOutput:\n```\nl  -->  <itertools._grouper object at 0x7f6bdab18160>  -->  [\'l\']\ne  -->  <itertools._grouper object at 0x7f6bdab12748>  -->  [\'e\', \'e\']\nt  -->  <itertools._grouper object at 0x7f6bdab12d30>  -->  [\'t\']\nc  -->  <itertools._grouper object at 0x7f6bdab12748>  -->  [\'c\']\no  -->  <itertools._grouper object at 0x7f6bdab12d30>  -->  [\'o\']\nd  -->  <itertools._grouper object at 0x7f6bdab12748>  -->  [\'d\']\ne  -->  <itertools._grouper object at 0x7f6bdab12d30>  -->  [\'e\']\n```
[]