Skip to content

Commit 15798b6

Browse files
committed
Day 5 - Changes
1 parent 8ef9147 commit 15798b6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/main/scala/com/kishan/scala/leetcode/juneChallenges/RandomPickWithWeight.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class RandomPickWithWeight(_w: Array[Int]) {
5454
private var preSum: Array[Int] = _w.scan(0)((a, b) => a + b).drop(1)
5555

5656
def pickIndex(): Int = {
57-
val randomNumber = random.nextInt(totalSum) + 1
57+
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.
5858
var head = 0
5959
var tail = preSum.length - 1
6060
var mid: Int = head + (tail - head) / 2

0 commit comments

Comments
 (0)