knuth shuffle 从前向后决定排列元素实现问题
1 2 3 4 5 6 7 | public void shuffle2( int [] arr) { Random random = new Random(); for ( int i = 0 ; i < arr.length; i++) { int choseIndex = random.nextInt(arr.length - i) + i; swap(arr, choseIndex, i); } } |
老师,从前向后决定排列元素这种实现不对吗,我想了几遍好像没什么问题,但是通不过leetcode的检查
9
收起
正在回答 回答被采纳积分+1
1回答
liuyubobobo
2022-11-05 11:31:20
请把能提交给 Leetcode 的完整代码给我。谢谢。
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧