Given a string s, the power of the string is the maximum length of a non-empty substring that contains only one unique character.
Return the power of the string.
 
Example 1:
Input: s = "leetcode"
Output: 2
Explanation: The substring "ee" is of length 2 with the character 'e' only.

Example 2:
Input: s = "abbcccddddeeeeedcba"
Output: 5
Explanation: The substring "eeeee" is of length 5 with the character 'e' only.

Example 3:
Input: s = "triplepillooooow"
Output: 5

Example 4:
Input: s = "hooraaaaaaaaaaay"
Output: 11

Example 5:
Input: s = "tourist"
Output: 1

 
Constraints:

1 <= s.length <= 500
s contains only lowercase English letters.

Difficulty: introductory

Starter code:

class Solution:
    def maxPower(self, s: str) -> int:
        

Solutions:
class Solution:
    def maxPower(self, s: str) -> int:
        n = len(s) 
        count = 0
        res = s[0] 
        cur_count = 1
  
        # Traverse string except  
        # last character 
        for i in range(n): 
          
            # If current character  
            # matches with next 
            if (i < n - 1 and 
                s[i] == s[i + 1]): 
                cur_count += 1
  
            # If doesn't match, update result 
            # (if required) and reset count 
            else: 
                if cur_count > count: 
                    count = cur_count 
                    res = s[i] 
                cur_count = 1
        return count 
       
        
        


class Solution:
    def maxPower(self, s: str) -> int:
        cnt = 0
        current = s[0]
        current_cnt = 1
        for l in s[1:]:
            if l == current:
                current_cnt += 1
            else:
                if current_cnt > cnt:
                    cnt = current_cnt
                current = l
                current_cnt = 1
        if current_cnt > cnt:
            cnt = current_cnt
        return cnt

class Solution:
    def maxPower(self, s: str) -> int:

        count = 0
        new_count = 0
        for i,char in enumerate(s):

            print(char)
            try:
                if s[i+1] == char:
                    new_count += 1
                else:
                    print('afwww')
                    if new_count >= count:
                        count = new_count
                    new_count = 0
            except:
                print('sefesf')
                if new_count >= count:
                    print('sfwafawfawfawfawfawf')
                    count = new_count
                    new_count = 0
                break

        return count+1


class Solution:
    def maxPower(self, s: str) -> int:
        c = {'power': 1}
        for i in range(len(s)) :
            if i == len(s)-1 :
                break
            if ord(s[i]) == ord(s[i+1]) :
                c['power'] += 1

            else:
                c['new start#%s' % i] = c['power']
                c['power'] = 1
        return max(c.values())

class Solution:
    def maxPower(self, s: str) -> int:
        power = 1
        max_power = 0
        for idx, i in enumerate(s):
            if len(s) < 2:
                return len(s)
            if idx == 0: 
                pass
            elif i == s[idx -1]:
                power += 1
                print(f' i is {i}, power is {power}')
            else:
                print(f' i is {i}, power is {power}')
                if power > max_power:
                    max_power = power
                power = 1
        return max(power, max_power)

class Solution:
    def maxPower(self, s: str) -> int:
        '''
            does: given a string s, the power of the string is the maximum length of 
                  a non-empty substring that contains only one unique character.
            parameters: s
            returns: the power of the string.
        '''
        # initialize the letter to None
        letter = None
        # initialize the temporary length and maximum length to 0
        length = 0
        max_length = 0

        # loop through the string
        for i in s:

            # if encountered the same letter, length plus one
            if i == letter:
                length += 1
                # set maximum length to the max of (max_length, length, 1)
                max_length = max(max_length, length)

            # if encountered a different letter
            else:
                # set maximum length to the max of (max_length, length, 1)
                max_length = max(max_length, length, 1)
                # reset the length to 0
                length = 1
                # reset the target to current letter
                letter = i
            print(i, max_length)

        return max_length

class Solution:
    def maxPower(self, s: str) -> int:
        z=[]
        c=0
        if len(s)==1:
            return 1
        for i in range(len(s)-1):
            if s[i]==s[i+1]:
                c=c+1
            else:
                z.append(c)
                c=0
        z.append(c)
        return max(z)+1


class Solution:
    def maxPower(self, s: str) -> int:
        if len(s) <= 1:
            return len(s)
        last_char = s[0]
        count = 1
        max_count = 0
        for c in s[1:]:
            if c == last_char:
                count += 1      
            else:
                if count > max_count:
                    max_count = count
                count =1 
                
            last_char =c
        if count > max_count:
            max_count = count
            
        return max_count


class Solution:
    def maxPower(self, s: str) -> int:
        prev = None
        count = 0
        max_count = 0
        for char in s:
            if char == prev:
                count +=1
            else:
                prev = char
                count =1
            max_count = max(max_count,count)
        return max_count

class Solution:
    def maxPower(self, s: str) -> int:
        
        seq = 1
        max_seq = 1
        
        for i in range(1, len(s)):
            
            if s[i] == s[i-1]:
                seq += 1
            else:
                max_seq = max(max_seq, seq)
                seq = 1
                
        max_seq = max(max_seq, seq)
        return max_seq
            


class Solution:
    def maxPower(self, s: str) -> int:
        count=0
        max_count=0
        previous=None
        for c in s:
            if c!=previous:
                previous=c
                count=1
            else:
                count+=1
            max_count=max(max_count,count)
        return max_count

class Solution:
    def maxPower(self, s: str) -> int:
        # Assign variables
        ans = 0
        consec_count_per_letter = 1
        prev_letter = s[0]

        # Return 1 when the length of the input is 1
        if len(s) == 1:
            return 1

        # Loop from 1 to the length of the input
        for i in range(1, len(s)):
            # If the current letter is the same as the prev letter,
            # then add 1 to consec_count_per_letter
            if s[i] == prev_letter:
                consec_count_per_letter += 1
            else:
                consec_count_per_letter = 1

            # Update the prev letter
            prev_letter = s[i]
            # Update the answer with a maximum
            # between the answer and consec_count_per_letter
            ans = max(ans, consec_count_per_letter)

        return ans


class Solution:
    def maxPower(self, s: str) -> int:
        c = 1
        maxc = c
        for i in range(len(s)-1): 
            if s[i] == s[i+1]: 
                c +=1
                maxc = max(maxc, c)
            else: 
                c = 1
        
        return maxc


class Solution:
    def maxPower(self, s: str) -> int:
        maxcount  = 1
        i = 0 
        while  i < len(s)-1 :
            count = 1
            while i < len(s)-1 and s[i] == s[i+1] :
                i = i +1 
                count = count +1 
            if( count > maxcount ) :
                maxcount = count
            if ( i <len(s) -1) :
                i = i+1
        return maxcount