不一样的解法
Function 最小代价(数字)
If IsNumeric(数字) = False or Len(数字) = 1 Then Exit Function
Dim sNum, result
sNum = CStr(数字)
If 数字 < 0 Then
result = For_最小代价(StrReverse(Replace(sNum, "-", "")),9,0,-1)
Else
result = For_最小代价(StrReverse(sNum),0,9,1)
End If
If 数字 < 0 Then result = "-"&result
最小代价 = Clng(result)
End Function
Function For_最小代价(sNum,start,finish,st)
For i = start To finish step st
result = Replace(sNum, Cstr(i), "", 1, 1)
If Len(result) < Len(sNum) Then
For_最小代价 = StrReverse(result)
Exit Function
End If
Next
End Function
1001=101
-152=-12
1=
123456=23456
654321=65432
45123=4523
点评
神梦科技
思路不错👍
发表于 2022/5/13 12:58:07