当前位置: 首页 > news >正文

做微商有什么好的货源网站林州市网站建设

做微商有什么好的货源网站,林州市网站建设,本科软件开发专业,做电视的视频网站设计一个支持在平均 时间复杂度 O(1) 下#xff0c; 执行以下操作的数据结构。 注意: 允许出现重复元素。 insert(val)#xff1a;向集合中插入元素 val。 remove(val)#xff1a;当 val 存在时#xff0c;从集合中移除一个 val。 getRandom#xff1a;从现有集合中随机…设计一个支持在平均 时间复杂度 O(1) 下 执行以下操作的数据结构。 注意: 允许出现重复元素。 insert(val)向集合中插入元素 val。 remove(val)当 val 存在时从集合中移除一个 val。 getRandom从现有集合中随机获取一个元素。每个元素被返回的概率应该与其在集合中的数量呈线性相关。 示例: // 初始化一个空的集合。 RandomizedCollection collection new RandomizedCollection(); // 向集合中插入 1 。返回 true 表示集合不包含 1 。 collection.insert(1); // 向集合中插入另一个 1 。返回 false 表示集合包含 1 。集合现在包含 [1,1] 。 collection.insert(1); // 向集合中插入 2 返回 true 。集合现在包含 [1,1,2] 。 collection.insert(2); // getRandom 应当有 2/3 的概率返回 1 1/3 的概率返回 2 。 collection.getRandom(); // 从集合中删除 1 返回 true 。集合现在包含 [1,2] 。 collection.remove(1); // getRandom 应有相同概率返回 1 和 2 。 collection.getRandom(); 代码 class RandomizedCollection {MapInteger,Integer mapnew HashMap();LinkedListInteger listnew LinkedList();//插入的数字链表MapInteger,Boolean booleanMapnew HashMap();//记录当前索引中的数字是否可选MapInteger,LinkedListInteger queueMapnew HashMap();//数字对应的在数字链表的索引/** Initialize your data structure here. */public RandomizedCollection() {}/** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */public boolean insert(int val) {list.addLast(val);booleanMap.put(list.size()-1,true);if(!queueMap.containsKey(val)){queueMap.put(val,new LinkedList());}queueMap.get(val).add(list.size()-1);//插入当前数字的数字链表的索引if(map.containsKey(val)map.get(val)0){map.put(val,map.get(val)1);return false;}else{map.put(val, 1);return true;}}/** Removes a value from the collection. Returns true if the collection contained the specified element. */public boolean remove(int val) {if(!queueMap.containsKey(val)||queueMap.get(val).isEmpty()) return false;int curqueueMap.get(val).removeFirst();//移出索引链表booleanMap.put(cur,false);//标记为不可选if(map.containsKey(val)map.get(val)0){map.put(val,map.get(val)-1);return true;}else return false;}/** Get a random element from the collection. */public int getRandom() {Random randomnew Random();int crandom.nextInt(list.size());while (!booleanMap.get(c))//跳过不可选的位置crandom.nextInt(list.size());return list.get(c);}} /*** Your RandomizedCollection object will be instantiated and called as such:* RandomizedCollection obj new RandomizedCollection();* boolean param_1 obj.insert(val);* boolean param_2 obj.remove(val);* int param_3 obj.getRandom();*/
http://www.pierceye.com/news/785451/

相关文章:

  • 成都门户网站建设多少钱聚合广告联盟
  • 坦克大战网站开发课程设计报告软文营销的本质
  • 美食网站开发网站登录验证码是怎么做的
  • 电子商务网站排名辽宁省建设工程信息网业绩公示
  • 天津建设科技杂志的官方网站wordpress cnzz插件
  • 滨州建设网站太原网站建设优化
  • 记事本做网站怎么改字体包装设计模板设计素材
  • 下载软件的网站推荐thinkphp和wordpress
  • 青海省城乡和住房建设厅网站合肥小吃培训网页设计
  • 财经门户网站建设django校园网站开发
  • 泉州网站建设报价广东建设厅网站
  • 建设网站的源代码的所有权wordpress网站打开慢
  • 印度外贸网站有哪些家居小程序源码下载
  • 上海网站建设中心pc官方网站
  • 深圳企业网站制作公司查询西安网站设计哪家好
  • 大埔做网站手机qq邮箱发布了wordpress
  • 寻找南昌网站设计单位网站建设 中企动力医院
  • 中间商可以做网站吗平面广告设计师的工作内容
  • 网站建设用户分析做网站有什么软件
  • 洛阳网站建设启辰网络wordpress怎么破解查看
  • 长沙市网站设计公司厦门建设网站建站
  • 网站做链轮会被惩罚吗网站开发系统
  • 一般做企业网站需要什么资料WordPress情侣博客模板
  • 网站开发教程公司哪些官网用wordpress
  • redis网站开发教程创建app软件
  • 企业网站新闻wp怎么做合肥环保公司网站建设
  • 怎么仿一个复杂的网站wordpress描述怎么改
  • php 如何用op浏览器开发手机网站app开发制作哪种快
  • 网站维护主要有哪些内容和方法网页制作需要学多久
  • 机械加工网站模板做蛋糕比较火的网站