查找整数范围的词典最小值的有效方法
给定两个正整数,例如 M 和 N,其中 M < N,找到以十进制 ASCII 表示且不带前导零的从 M 到 N 的整数字符串的字典顺序中的最小值的最有效算法是什么?例如,对于 [200, 10890],答案是“1000”,对于 [298, 900],答案是“298”。
Given two positive integers, say M and N, with M < N, what is the most efficient algorithm to find the minimum in lexicographical order of the strings of the integers from M to N represented in base ten ASCII without leading zeros? For example, for [200, 10890], the answer is '1000', for [298, 900], the answer is '298'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的直觉可能是正确的,为此有一个恒定时间算法。您首先找到最小的第一个数字,然后找到最小的第二个数字,依此类推。
I think you're probably right in your intuition that there's a constant-time algorithm for this. You'd first find the smallest first digit, then the smallest second digit, etc.