给出一个字串。返回一个相邻接的相同字符的个数的最大值。
例如:BBBCCGGGG 结果是4
abc 结果是1
谢谢!
------解决方案--------------------
凑活看吧...
public class Test11 {
public static void main(String[] args) throws Exception {
String s = "cccdddssss ";
char c;
c = s.charAt(0);
int count = 1;
int max = Integer.MIN_VALUE;
for (int i = 1; i < s.length(); i++) {
if (s.charAt(i) == c)
count++;
else {
if (count > max)
max = count;
c = s.charAt(i);
count = 1;
}
}
if (count > max)
max = count;
System.out.println(max);
}
}