← 返回 atlassian 的题目列表O(1) Data Structure Using Double Linked List
类型:online_judge
Design a data structure with O(1) operations.
Implement a data structure supporting the following operations:
insert(val): Inserts an element with value val in O(1) time.
remove(val): Removes an element with value val in O(1) time. If the element does not exist, do nothing.
getRandom(): Returns a random element among all elements with O(1) time.
Implement this structure using a double linked list.
Example
Input
insert(1)
insert(2)
remove(1)
getRandom()
Output
2