public class OneDigitDifference {
public int getSmallest(int N) {
if(N == 0)
return 1;
int[] is = new int[10];
for(int i = 0; i < 10; i++, N /= 10)
is[i] = N % 10;
for(int i = 9; i >= 0; i--)
if(is[i] > 0) {
is[i] = 0;
break;
}
int ret = 0;
for(int i = 9; i >= 0; i--)
ret = ret * 10 + is[i];
return ret;
}
}
cHVibGljIGNsYXNzIE9uZURpZ2l0RGlmZmVyZW5jZSB7CgogICAgcHVibGljIGludCBnZXRTbWFsbGVzdChpbnQgTikgewogICAgICAgIGlmKE4gPT0gMCkKICAgICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgaW50W10gaXMgPSBuZXcgaW50WzEwXTsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgMTA7IGkrKywgTiAvPSAxMCkKICAgICAgICAgICAgaXNbaV0gPSBOICUgMTA7CiAgICAgICAgZm9yKGludCBpID0gOTsgaSA+PSAwOyBpLS0pCiAgICAgICAgICAgIGlmKGlzW2ldID4gMCkgewogICAgICAgICAgICAgICAgaXNbaV0gPSAwOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICBpbnQgcmV0ID0gMDsKICAgICAgICBmb3IoaW50IGkgPSA5OyBpID49IDA7IGktLSkKICAgICAgICAgICAgcmV0ID0gcmV0ICogMTAgKyBpc1tpXTsKICAgICAgICByZXR1cm4gcmV0OwogICAgfQp9