Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c4b947e

Browse files
✨feat: Add 398
1 parent d5add46 commit c4b947e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

‎LeetCode/391-400/398. 随机数索引(中等).md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class Solution {
7474

7575
`nums` 并不是在初始化时完全给出,而是持续以「流」的形式给出,且数据流的很长,不便进行预处理的话,我们只能使用「蓄水池抽样」的方式求解。
7676

77+
**不了解「蓄水池抽样」的同学可以看前置 🧀 : [多语言入门「蓄水池抽样」知识点](https://mp.weixin.qq.com/s?__biz=MzU4NDE3MTEyMA==&mid=2247490892&idx=1&sn=c1fe373edc88142cbabd383ef3c0669b)**
78+
7779
具体的,我们在每次 `pick` 时对流进行遍历,由于数据流很大,我们不能在遍历过程中使用诸如数组的容器存储所有满足条件的下标,只能对于每个 $nums[i] = target$ 执行「是否要将 $i$ 作为最新答案候选」的操作。
7880

7981
假设共有 $m$ 个下标满足 $nums[i] = target,ドル我们需要做到以 $\frac{1}{m}$ 概率返回任一坐标。

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /