Function to find the total number of substring having only ones
def countOfSubstringWithOnlyOnes ( s ) : NEW_LINE INDENT count = 0 NEW_LINE res = 0 NEW_LINE for i in range ( 0 , len ( s ) ) : NEW_LINE INDENT if s [ i ] == '1' : NEW_LINE INDENT count = count + 1 NEW_LINE DEDENT else : NEW_LINE INDENT count = 0 ; NEW_LINE DEDENT res = res + count NEW_LINE DEDENT return res NEW_LINE DEDENT