We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8ef9147 commit 15798b6Copy full SHA for 15798b6
src/main/scala/com/kishan/scala/leetcode/juneChallenges/RandomPickWithWeight.scala
@@ -54,7 +54,7 @@ class RandomPickWithWeight(_w: Array[Int]) {
54
private var preSum: Array[Int] = _w.scan(0)((a, b) => a + b).drop(1)
55
56
def pickIndex(): Int = {
57
- val randomNumber = random.nextInt(totalSum) + 1
+ val randomNumber = random.nextInt(totalSum) + 1 // We don't want randomNumber as 0 if we get 0. Inorder to avoid that we are adding 1.
58
var head = 0
59
var tail = preSum.length - 1
60
var mid: Int = head + (tail - head) / 2
0 commit comments