90哦吼

关注

leetcode每日-2022.04.25-398. 随机数索引

90哦吼

关注

阅读 38

2022-04-25

class Solution {
public:
    vector<int> res;
    Solution(vector<int>& nums) {
        res = nums;
    }
    
    int pick(int target) {
        int c = 0;
        int index = 0;
        for (int i = 0; i < res.size(); ++i){
            if (res[i] == target){
                c++;
                if (rand() % c == 0) index = i;
            }
        }
        return index;
    }
};

相关推荐

大柚子top

LeetCode 398、随机数索引

大柚子top 65 0 0

兔八哥软件爱分享

LeetCode——398. 随机数索引

兔八哥软件爱分享 35 0 0

AbrahamW

398.随机数索引

AbrahamW 89 0 0

骨灰级搬砖工

水塘抽样及LeetCode398题随机数索引

骨灰级搬砖工 42 0 0

zidea

每日一题-LeetCode398-随机数索引-数学-蓄水池抽样

zidea 58 0 0

雨鸣静声

【Leetcode】每日一题:随机数索引

雨鸣静声 62 0 0

颜娘娘的碎碎念

LeetCode_随机数索引

颜娘娘的碎碎念 38 0 0

爪哇驿站

LeetCode中等题之随机数索引

爪哇驿站 34 0 0

_阿瑶

398. 随机数索引 :「哈希表预处理」&「蓄水池抽样」

_阿瑶 62 0 0

琛彤麻麻

随机数

琛彤麻麻 183 0 0

精彩评论(0)

0 0 举报