Count Binary Substrings


My elementary solution's not as beautiful:
class Solution(object): def countBinarySubstrings(self, s): ans=0 count=[0,0] i=0 while i<len(s): count[0]=0 while i<len(s) and s[i]==s[0]: count[0]+=1 i+=1 ans+=min(count[0],count[1]) count[1]=0 while i<len(s) and s[i]!=s[0]: count[1]+=1 i+=1 ans+=min(count[0],count[1]) return ans


My two pointer solution:
class Solution(object): def countBinarySubstrings(self, s): """ :type s: str :rtype: int """ res = 0 for i in range(0, len(s)1): if s[i] != s[i+1]: res += self.helper(i, s) return res def helper(self, i, s): count = 1 while icount >= 0 and i+1+count < len(s) and s[icount] == s[i] and s[i+1+count] == s[i+1]: count += 1 return count