I\'m working on some piece of code, which is quite hot, and I need to add elements of one LinkedList
(l1
) to another LinkedList
(
No. You cannot add two java.util.LinkedList
s to output another one in constant time O(1).
Conceptually, you can indeed add two Linked List data structures together in constant time O(1) but they'll need to be implemented in the right way. As you mention, the implementation should combine the two lists by joining the node of the last to the node of the first and does not iterate over either list.