Count of 1 | C # implementation of the above approach ; Function to return the count of required characters ; While there are characters left ; Single bit character ; Two - bit character ; Update the count ; Driver code
using System ; class GFG { static int countChars ( string str , int n ) { int i = 0 , cnt = 0 ; while ( i < n ) { if ( str [ i ] == '0' ) i += 1 ; else i += 2 ; cnt += 1 ; } return cnt ; } public static void Main ( ) { string str = "11010" ; int n = str . Length ; Console . WriteLine ( countChars ( str , n ) ) ; } }