30:00
The power of a string is the length of its longest non-empty substring that contains only one distinct character. Given a string s, return its power.
s
1≤s.length≤5001 \leq s.\text{length} \leq 5001≤s.length≤500
s consists of only lowercase English letters.
Run code to see results.
s cut into runs of one letter: current run · best run
★ 1
The first letter 'l' starts a run of length 1, and it is also the best run so far.
run
1
best
The power of a string is the length of its longest block of one repeated letter. Walk the string once, growing a run counter while the letter repeats and resetting it when the letter changes; the largest run seen is the answer. "abbcccddddeeeeedcba" has power 5 from "eeeee".