Skip to content

Latest commit

 

History

History
30 lines (26 loc) · 738 Bytes

Question_1446.md

File metadata and controls

30 lines (26 loc) · 738 Bytes

LeetCode Records - Question 1446 Consecutive Characters

Attempt 1: Record the current and the maximum counts

class Solution {
    public int maxPower(String s) {
        char[] arr = s.toCharArray();
        int maxCount = 0;
        int count = 1;
        char prevCh = arr[0];

        for (int i = 1; i < arr.length; i++) {
            if (arr[i] == prevCh) {
                count++;
            } else {
                maxCount = Math.max(maxCount, count);
                count = 1;
                prevCh = arr[i];
            }
        }
        maxCount = Math.max(maxCount, count);

        return maxCount;
    }
}
  • Runtime: 1 ms (Beats: 100.00%)
  • Memory: 42.32 MB (Beats: 7.61%)