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. HTML Tags

    While some tags have a very specific purpose, such as image and video tags, most tags are used to de ...

  2. docker之docker-machine用法

    转自:https://www.cnblogs.com/jsonhc/p/7784466.html docker-machine 是docker官方提供的docker管理工具.通过docker-mach ...

  3. Mongodb集群节点故障恢复场景分析(转)

    一个适当配置的Mongodb分片集群是没有单点故障.本文描述了分片集群中存在的几种不同的潜在的节点故障场景,以及Mongodb对这些节点故障是怎么处理的.1.Mongos节点宕机一个Mongos进程应 ...

  4. 【BUG记录】记一次游戏越来越卡的BUG

    U3D的MOBA项目,测试过程中,10分钟以后,游戏帧率开始缓慢下降,约3-5分钟后,由60帧下降到小于10帧,编辑器模式. 打开profiler,看到CPU占用非常高,每帧都有24K的GC, 时间占 ...

  5. Ftp命令使用

    FTP> ? 显示 ftp 命令说明.? 与 help 相同. 格式:?  [command] 说明:[command] 指定需要帮助的命令名称.如果没有指定 command,ftp将显示全部命 ...

  6. JAVA字符串格式化-String.format()的使用【转】

    原文地址:https://blog.csdn.net/lonely_fireworks/article/details/7962171 常规类型的格式化 String类的format()方法用于创建格 ...

  7. Hibernate学习笔记3.1(Hibernate关系映射)

    主要指对象之间的关系 1.一对一关联 一对一单项外键关联 比如说一夫一妻 Wifi.java package com.bjsxt.hibernate; import javax.persistence ...

  8. fwrite()中参数含义——size和count经常用搞反

    函数原型:size_t fwrite(const void* buffer, size_t size, size_t count, FILE* stream);   注意:这个函数以二进制形式对文件进 ...

  9. C# 反射赋值

    tb_Projects model = new tb_Projects(); model.OwnerId = ; string FieldName = "OwnerId";//字段 ...

  10. Oracle 查询表的字段注释

    SELECT TABLE_NAME, COLUMN_NAME, COMMENTSFROM USER_COL_COMMENTSWHERE TABLE_NAME = 'TB_MENU';