Design a data structure that supports all following operations in averageO(1) time. Note: Duplicate elements are allowed. insert(val): Inserts an item val to the collection. remove(val): Removes an item val from the collection if present. getRandom:
设计一个支持在平均 时间复杂度 O(1) 下, 执行以下操作的数据结构.注意: 允许出现重复元素. insert(val):向集合中插入元素 val. remove(val):当 val 存在时,从集合中移除一个 val. getRandom:从现有集合中随机获取一个元素.每个元素被返回的概率应该与其在集合中的数量呈线性相关.示例:// 初始化一个空的集合.RandomizedCollection collection = new RandomizedCollection();
第一种情况:iframe中不存在name和id的方法:(通过contentWindow获取) var iframe = document.getElementsByTagName('iframe')[0];var ifr_document = iframe.contentWindow.document;//iframe中的文档内容 或者: var _iframe = document.getElementByIdx_x('iframeId').contentWindow; var _div