Greedy Algorithms - Remove K Digits (Smallest Number)
The following code attempts to remove k digits from a number string to get the smallest number. Which line contains a subtle bug that causes incorrect output on inputs with leading zeros?
```python
def removeKdigits(num: str, k: int) -> str:
stack = []
for digit in num:
while k > 0 and stack and stack[-1] > digit:
stack.pop()
k -= 1
stack.append(digit)
while k > 0:
stack.pop()
k -= 1
result = ''.join(stack)
return result if result else '0'
```
