List
List (Double Linked List in C++ STL)
splice(iterator of list1, list2)
copy whole list2 into where iterator points at in list1 and empty list2.
splice(iterator1 of list1, list2, iterator2 of list2)
copy the only element where iterator2 at in list2 into where iterator1 at in list1.
splice(iterator1 of list1, list2, start-iter of list2, end-iter of list2)
copy the all elements in the range of start to end iterators in list2 and put them into where iterator1 at in list1.
remove(key)
vector doesn't have this function.
delete specific value in the list.
erase(key)
delete specific position in the list, usually need to use iterator.
pop_back() & pop_front()
push_back() & push_front()
front() & back()
Approach1: List
Time Complexity: O(1) both for get and put.
Space Complexity: O(N), where N is the capacity.
Approach2: List + Splice (faster than approach 1)
Time Complexity: O(1) both for get and put.
Space Complexity: O(N), where N is the capacity.
find()
find(deque.begin(),deque.end(),target) == deque.end() means the target doesn't exist in the deque.
[Medium] No.353 Design Snake Game