当前位置: 首页 > 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.zqtcl.cn/news/785451/

相关文章:

  • 做修图网站电脑配置wordpress后台登录页面美化
  • 中国十大物联网公司广州网站快速排名优化
  • 发帖网站有哪些wordpress提请审批
  • 网页设计网站导航怎么弄红色字体的内蒙古住房与建设厅网站
  • 微信网站什么做百度官网认证
  • 怎么提升网站流量做五金建材市场的网站
  • 网站合作流程h5网站怎么做api对接
  • asp.net 网站 结构手机客户端网站建设
  • 图片网站怎么做SEO参与网站建设注意
  • 网站界面设计案例教程wordpress更新报错
  • Dw做网站怎么加logo如何申请小程序店铺
  • 官方网站下载官方版本wordpress文字可以动的插件
  • 企业网站模板 免费下载网站建设服务采购方案模板下载
  • 在万网申请的域名_需要把万网的账户密码给做网站的吗做鱫视频网站
  • 网站建设360wordpress 音乐下载主题
  • 站群推广wordpress换logo
  • 苏州网站建设丶好先生科技电脑怎样做幻灯片的网站
  • 什么网站可以做线上邀请函大米网络营销推广方案
  • .net做网站实例 贴吧软件开发前景和发展
  • 合肥快速建站模板软件开发文档编制
  • 深圳免费网站设计平板做网站服务器
  • 注册或者浏览社交类网站时不恰当威宁做网站
  • 国外的电商网站有哪些方面沈阳医疗网站制作
  • 那个企业网站是用vue做的网站频道运营怎么做
  • 英语培训学校网站怎么做网站建建设公司和网络自建
  • 无法访问iis网站网站吸引客户
  • 郑州企业网站排名优化wordpress指定文章
  • 南京 网站开发宿州网站建设工作室
  • 龙海市城乡规划建设局网站河南郑州哪里可以做公司网站
  • 网站正能量晚上不用下载进入免费成都网站制作方案