Given a binary string , count number of substrings that start and end with 1. | A simple C # program to count number of substrings starting and ending with 1 ; Initialize result ; Pick a starting point ; Search for all possible ending point ; Driver Code
using System ; class GFG { public virtual int countSubStr ( char [ ] str , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == '1' ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( str [ j ] == '1' ) { res ++ ; } } } } return res ; } public static void Main ( string [ ] args ) { GFG count = new GFG ( ) ; string s = "00100101" ; char [ ] str = s . ToCharArray ( ) ; int n = str . Length ; Console . WriteLine ( count . countSubStr ( str , n ) ) ; } }