Skip to content

Instantly share code, notes, and snippets.

@kingsamadesu
Created December 3, 2020 21:30
Show Gist options
  • Select an option

  • Save kingsamadesu/6de62b534b4c669ea9fd3973b6fe71ab to your computer and use it in GitHub Desktop.

Select an option

Save kingsamadesu/6de62b534b4c669ea9fd3973b6fe71ab to your computer and use it in GitHub Desktop.
1446. Consecutive Characters -with java- (leetcode.com)
/*
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