mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-13 12:19:54 +08:00
Fix bucket_sort.
This commit is contained in:
@@ -17,7 +17,7 @@ func bucketSort(nums []float64) {
|
||||
// 1. 将数组元素分配到各个桶中
|
||||
for _, num := range nums {
|
||||
// 输入数据范围 [0, 1),使用 num * k 映射到索引范围 [0, k-1]
|
||||
i := int(num) * k
|
||||
i := int(num * float64(k))
|
||||
// 将 num 添加进桶 i
|
||||
buckets[i] = append(buckets[i], num)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user