Leetcode - Perfect Squares
Leetcode - Valid Palindrome II

Leetcode - Consecutive Characters

violet posted @ Jul 03, 2020 12:08:21 PM in 算法 with tags Algorithm Golang array , 271 阅读

https://leetcode.com/problems/consecutive-characters/

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.

 

func maxPower(s string) int {
    i := 0
    count := 1
    for i < len(s) {
        j := i + 1
        for j < len(s) && s[j] == s[i] {
            j++
        }
        if j - i > count {
            count = j - i
        }
        i = j
    }
    
    return count
}
NCERT Computer Quest 说:
Sep 24, 2022 12:16:13 AM

In modern days, Computer Education is most important for everyone and its one of the fastest growing career fields. A career in the field of computer science has been proven to be a worthwhile direction for any young enthusiast. It helps them to aim for excellent jobs in the future and succeed in it. NCERT Computer Question Paper Class 9 The computer has become a standard of education throughout the world. This makes computer education important.In modern days, Computer Education is most important for everyone and its one of the fastest growing career fields.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter