题解 | #求最大连续bit数#
求最大连续bit数
https://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
(1)转换为二进制
(2)设定俩个指针
using System; namespace HJ86{ class Solution{ public static void Main(){ var input = Convert.ToInt32(Console.ReadLine()); string str = Convert.ToString(input,2); int res = 0, left =0; for(int right = 0; right < str.Length; right++){ if(str[right] == '0'){ left = right+1; } res = Math.Max(res,right-left+1); } Console.WriteLine(res); } } }