import java.io.*;
import java.util.*;
class myCode
{
public int atMost2( String s){
if(s == null ) return 0;
int[] hash = new int[26];
int max = 0;
int start =0;
int count = 0;
for(int i = 0; i < s.length(); i++){
char c = s.charAt(i);
hash[c-'a']++;
if(hash[c-'a'] == 1) count++;
while(count > 2){
char st = s.charAt(start++);
hash[st-'a']--;
if(hash[st-'a'] == 0) count--;
}
max = Math.max(max, i - start + 1);
}
return max;
}
public static void main (String[] args) throws java.lang.Exception
{
myCode test = new myCode();
System.out.println(test.atMost2("eceeeeeeeeeeba"));
}
}
网友评论