<awangdev>402. Remove K Digits_1.java
public String removeKdigits(String num, int k) {
        Stack<Character> stack = new Stack<>();
        
        int i = 0, n = num.length();
        while (i < n) {
            char c = num.charAt(i++);
            while (k > 0 && !stack.isEmpty() && stack.peek() > c) {
                stack.pop();
                k--;
            }
            stack.push(c);
        }
        
        while (k-- > 0) stack.pop();
        
        StringBuffer sb = new StringBuffer();
        while(!stack.isEmpty()) sb.append(stack.pop());
        sb.reverse();
        while(sb.length() > 0 && sb.charAt(0) == '0') sb.deleteCharAt(0);
        
        return sb.length() == 0 ? "0" : sb.toString();
    }
public String var_0 ( String var_2 , int var_3 ) {
  Stack < Character > var_6 = new Stack < > ( ) ;
  int var_8 = 0 , var_10 = var_2 . length ( ) ;
  while ( var_8 < var_10 ) {
    char var_12 = var_2 . charAt ( var_8 ++ ) ;
    while ( var_3 > 0 && ! var_6 . isEmpty ( ) && var_6 . peek ( ) > var_12 ) {
      var_6 . pop ( ) ;
      var_3 -- ;
    }
    var_6 . push ( var_12 ) ;
  }
  while ( var_3 -- > 0 ) var_6 . pop ( ) ;
  StringBuffer var_18 = new StringBuffer ( ) ;
  while ( ! var_6 . isEmpty ( ) ) var_18 . append ( var_6 . pop ( ) ) ;
  var_18 . reverse ( ) ;
  while ( var_18 . length ( ) > 0 && var_18 . charAt ( 0 ) == '0' ) var_18 . deleteCharAt ( 0 ) ;
  return var_18 . length ( ) == 0 ? "0" : var_18 . toString ( ) ;
}
