mirror of
https://github.com/krahets/hello-algo.git
synced 2025-02-02 22:43:50 +08:00
fix: change shuffle algo in the doc
This commit is contained in:
parent
e96272a06f
commit
52927cadad
@ -2337,7 +2337,7 @@ $$
|
||||
}
|
||||
// 随机打乱数组元素
|
||||
for (let i = 0; i < n; i++) {
|
||||
let r = Math.floor(Math.random() * n);
|
||||
let r = Math.floor(Math.random() * (i + 1));
|
||||
let temp = nums[i];
|
||||
nums[i] = nums[r];
|
||||
nums[r] = temp;
|
||||
@ -2381,7 +2381,7 @@ $$
|
||||
}
|
||||
// 随机打乱数组元素
|
||||
for (let i = 0; i < n; i++) {
|
||||
let r = Math.floor(Math.random() * n);
|
||||
let r = Math.floor(Math.random() * (i + 1));
|
||||
let temp = nums[i];
|
||||
nums[i] = nums[r];
|
||||
nums[r] = temp;
|
||||
|
Loading…
Reference in New Issue
Block a user