牛客编程巅峰赛S2赛季第五场
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 返回符合题意的最长的子串长度
* @param x string字符串
* @return int整型
*/
public int Maximumlength (String x) {
// write code here
int l = x.length();
int[] a = new int[26];
int max = 0;
for (int i = 0, j = 0; i < l;) {
while (i < l && (a[13] == 0 || a[15] == 0 || a[24] == 0)) {
a[x.charAt(i) - 'a']++;
i++;
}
max = Math.max(max, i - j - 1);
while (a[13] != 0 && a[15] != 0 && a[24] != 0) {
a[x.charAt(j) - 'a']--;
j++;
}
if(i == l)
max = Math.max(max,i-j);
}
return max;
}
} #笔试题目#