Write a function that returns the smallest nonnegative number which can be generated by using all the digits with odd values of a given number.
Example:
number = 10430
Result: 13
这道题的核心是先从给定数字中筛出所有奇数位数字,再把这些数字按从小到大排序并拼接成最小的非负整数。比如 10430 中只有 1 和 3 是奇数数字,排序后得到 13。需要注意的是,如果没有任何奇数数字,则应返回 None;如果输入本身为负数,通常要按其绝对值提取数字后再处理。实现上可以先转成字符串遍历、过滤奇数字符,再排序组合,复杂度主要取决于数字位数,适合用简单的字符串与排序处理。
正文完