将n位数减少到可能的最低值

asp*_*rin -1 php

这似乎微不足道,但我感到困惑的是,我无法就此达成解决方案.我想要做的是:

Input ->  14025
Output -> 10245

Input ->  171
Output -> 117
Run Code Online (Sandbox Code Playgroud)

等等...

spl*_*h58 5

$input = 140205;

$temp = str_split($input);
sort($temp);
// find the 1st non-zero digit
$f = current(array_filter($temp));
// remove it from the array
unset($temp[array_search($f, $temp)]);
echo $output = $f . join($temp);  // 100245
Run Code Online (Sandbox Code Playgroud)

演示