Given an array w of positive integers, where w[i] describes the weight of index i, write a function pickIndex which randomly picks an index in proportion to its weight.

Note:

  1. 1 <= w.length <= 10000
  2. 1 <= w[i] <= 10^5
  3. pickIndex will be called at most 10000 times.

Example 1:

Input:
["Solution","pickIndex"]
[[[1]],[]]
Output: [null,0]

Example 2:

Input:
["Solution","pickIndex","pickIndex","pickIndex","pickIndex","pickIndex"]
[[[1,3]],[],[],[],[],[]]
Output: [null,0,1,1,1,0]

Explanation of Input Syntax:

The input is two lists: the subroutines called and their arguments. Solution's constructor has one argument, the array wpickIndex has no arguments. Arguments are always wrapped with a list, even if there aren't any.

题目

思路

代码

[leetcode]528. Random Pick with Weight按权重挑选索引的更多相关文章

  1. LeetCode 528. Random Pick with Weight

    原题链接在这里:https://leetcode.com/problems/random-pick-with-weight/ 题目: Given an array w of positive inte ...

  2. 【LeetCode】528. Random Pick with Weight 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/random-pi ...

  3. [LeetCode] Random Pick with Weight 根据权重随机取点

    Given an array w of positive integers, where w[i] describes the weight of index i, write a function  ...

  4. 528. Random Pick with Weight

    1. 问题 给定一个权重数组w,w[i]表示下标i的权重,根据权重从数组中随机抽取下标. 2. 思路 这道题相当于 497. Random Point in Non-overlapping Recta ...

  5. 528. Random Pick with Weight index的随机发生器

    [抄题]: Given an array w of positive integers, where w[i] describes the weight of index i, write a fun ...

  6. [Swift]LeetCode528. 按权重随机选择 | Random Pick with Weight

    Given an array w of positive integers, where w[i] describes the weight of index i, write a function  ...

  7. [LeetCode] 398. Random Pick Index ☆☆☆

    Given an array of integers with possible duplicates, randomly output the index of a given target num ...

  8. Random Pick with Weight

    Given an array w of positive integers, where w[i] describes the weight of index i, write a function  ...

  9. [leetcode] 398. Random Pick Index

    我是链接 看到这道题,想到做的几道什么洗牌的题,感觉自己不是很熟,但也就是rand()函数的调用,刚开始用map<int, vector<int >>来做,tle,后来就想着直 ...

随机推荐

  1. 一次UNITY闪退问题的定位心得

    最近项目测试发现,运行unity后不退出运行模式,玩了一局后点击 “再来一局”,反复十几局后unity崩掉. 经观察,发现在这十几局的过程中,unity占用内存不断上升,由3.2G左右上升到3.6G左 ...

  2. Jquery select chosen 插件注意点

    <select style="width:200px;" name="carId" data-placeholder="选择车辆牌照" ...

  3. 高并发架构技术|缓存失效、缓存穿透问题 PHP 代码解决

    问题描述 缓存失效: 引起这个原因的主要因素是高并发下,我们一般设定一个缓存的过期时间时,可能有一些会设置5分钟啊,10分钟这些:并发很高时可能会出在某一个时间同时生成了很多的缓存,并且过期时间在同一 ...

  4. 讲一讲Servlet和JSP的关系

    Test.jsp在运行时首先被解析成一个java类Test_jsp.java,该类继承于org.apache.jasper.runtime.HtppJspBase类,而Http又是继承HttpServ ...

  5. MyBatis对入参对象的属性空判断

      <!-- 查询学生list,like姓名 -->   <select id="getStudentListLikeName" parameterType=&q ...

  6. 23.week4

    调通了 剩下的就是核心的部分

  7. Hadoop分布式HA的安装部署

    Hadoop分布式HA的安装部署 前言 单机版的Hadoop环境只有一个namenode,一般namenode出现问题,整个系统也就无法使用,所以高可用主要指的是namenode的高可用,即存在两个n ...

  8. 安装opencv3.x卡在ICV: Downloading ippicv_linux_20151201.tgz...

    参考:http://blog.csdn.net/bobsweetie/article/details/52502741 可以自己下载: ICV: Downloading ippicv_linux_20 ...

  9. VMwear安装Centos7超详细过程

    本篇文章主要介绍了VMware安装Centos7超详细过程(图文),具有一定的参考价值,感兴趣的小伙伴们可以参考一下 1.软硬件准备 软件:推荐使用VMwear,我用的是VMwear 12 镜像:Ce ...

  10. DM 9000网卡驱动移植

    1. 由于内核已经带有DM9000 网卡的驱动,所以主要移植工作是在板文件中添加 platform_device 结构,并加入 ok6410_devices[] __initdata 数组. 代码如下 ...