MCPcopy Create free account
hub / github.com/LjyYano/LeetCode / pick

Method pick

src/main/java/L0398_RandomPickIndex.java:47–64  ·  view source on GitHub ↗

使用蓄水池抽样算法 1. 遍历数组,对于第 k 个等于 target 的数,以 1/k 的概率选择它 2. 这样可以保证每个等于 target 的索引被选中的概率相等

(int target)

Source from the content-addressed store, hash-verified

source not stored for this graph (policy: none)

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected