Amortized analysis for increment in counter |
import java . util . * ; class GFG { public static void main ( String args [ ] ) { String st = "10010111" ; char [ ] str = st . toCharArray ( ) ; int lengthh = st . length ( ) ; int i = lengthh - 1 ; while ( str [ i ] == '1' ) { str [ i ] = '0' ; i -- ; } if ( i >= 0 ) str [ i ] = '1' ; System . out . print ( str ) ; } }