Concatenate two java.util.LinkedList in constant time

前端 未结 3 1070
你的背包
你的背包 2021-01-17 16:14

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 (

3条回答
  •  再見小時候
    2021-01-17 16:43

    No. You cannot add two java.util.LinkedLists 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.

提交回复
热议问题