Created
December 3, 2020 21:30
-
-
Save kingsamadesu/6de62b534b4c669ea9fd3973b6fe71ab to your computer and use it in GitHub Desktop.
1446. Consecutive Characters -with java- (leetcode.com)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Your runtime beats 100.00 % of java submissions. | |
| Your memory usage beats 30.96 % of java submissions. | |
| */ | |
| class Solution { | |
| public int maxPower(String s) { | |
| int n = s.length(); | |
| int max = 0; | |
| int testmax = 0; | |
| char ele = s.charAt(0); | |
| for(int i = 0 ; i<n ; i++){ | |
| boolean test = s.charAt(i)==ele; | |
| if(test){ | |
| testmax++; | |
| } | |
| if(!(test)|i==n-1){ | |
| if(max<testmax){ | |
| max = testmax; | |
| } | |
| testmax = 1; | |
| ele = s.charAt(i); | |
| } | |
| } | |
| return max; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment