查找整数范围的词典最小值的有效方法

发布于 11-03 11:06 字数 144 浏览 5 评论 0原文

给定两个正整数,例如 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独享拥抱2024-11-10 11:06:59

我认为您的直觉可能是正确的,为此有一个恒定时间算法。您首先找到最小的第一个数字,然后找到最小的第二个数字,依此类推。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文