Longest Substring containing '1' | C # program for the above approach ; Function to find length of of longest substring containing '1' ; Count the number of contiguous 1 's ; Driver code
using System ; class GFG { static int maxlength ( String s ) { int n = s . Length , i , j ; int ans = 0 ; for ( i = 0 ; i <= n - 1 ; i ++ ) { if ( s [ i ] == '1' ) { int count = 1 ; for ( j = i + 1 ; j <= n - 1 && s [ j ] == '1' ; j ++ ) count ++ ; ans = Math . Max ( ans , count ) ; } } return ans ; } public static void Main ( String [ ] args ) { String s = "11101110" ; Console . Write ( maxlength ( s ) ) ; } }