halfrost / LeetCode-Go

✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解
https://books.halfrost.com/leetcode
MIT License
32.99k stars 5.7k forks source link

0164.Maximum Gap基数排序中缺少计数器更新导致BUG #88

Closed pench3r closed 3 years ago

pench3r commented 3 years ago

https://github.com/halfrost/LeetCode-Go/blob/master/leetcode/0164.Maximum-Gap/164.%20Maximum%20Gap.go#L69

原代码:

        for i := len(nums) - 1; i >= 0; i-- {
            tmp := count[(nums[i]/exp)%10]
            tmp--
            aux[tmp] = nums[i]
        }

缺少计数器更新,应更新为:

        for i := len(nums) - 1; i >= 0; i-- {
            tmp := count[(nums[i]/exp)%10]
            tmp--
            aux[tmp] = nums[i]
            count[(nums[i]/exp)%10] = tmp
        }
halfrost commented 3 years ago

@pench3r 您好,你指出的这里确实是我错了。我回翻了我的提交记录,之前确实是 AC 了,看来测试数据之前还比较弱。我加上了针对这里的测试用例了。一并都更新在代码文件里面了。LeetCode Cookbook 也更新了。谢谢大佬指出错误,非常感谢!🙏🏻