代码填空(满分6分)
下列代码求出一个二进制串中连续的1或连续的0出现的最大次数。请填缺失代码。
例如:s =
“101100111100011”
则返回:4
又例如:s=”0111100000”
则返回:5
public static int
getMaxContinuity(String s)
{
int max_1 = 0;
int max_0 =
0;
int
n_1 = 0; // 当前1连续的次数
int n_0
= 0; // 当前0连续的次数
for(int i=0; i<s.length();
i++)
{
if(s.charAt(i)==‘0‘)
{
n_0++;
________;
n_1=0
}
else
{
n_1++;
_________; n_0 =
0
}
http://jingztyl82.com
http://hongbsyu18.com
if(n_1 > max_1) max_1 =
n_1;
if(n_0 > max_0) max_0 = n_0;
}
return max_1>max_0? max_1 :
max_0);
}
原文:http://www.cnblogs.com/geziwu/p/3564479.html