Given a binary string , count number of substrings that start and end with 1. | A simple PHP program to count number of substrings starting and ending with 1 ; Pick a starting point ; Return count of possible pairs among m 1 's ; Driver Code
< ? php function countSubStr ( $ str ) { for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) { if ( $ str [ $ i ] == '1' ) { $ m ++ ; } } return $ m * ( $ m - 1 ) / 2 ; } $ str = "00100101" ; echo countSubStr ( $ str ) ; ? >