Amortized analysis for increment in counter |
#include <bits / stdc++.h> NEW_LINE using namespace std ; int main ( ) { char str [ ] = "10010111" ; int length = strlen ( str ) ; int i = length - 1 ; while ( str [ i ] == '1' ) { str [ i ] = '0' ; i -- ; } if ( i >= 0 ) str [ i ] = '1' ; printf ( " % ▁ s " , str ) ; }