Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
Example 1:
1 |
|
Related Topics: Linked List
解題邏輯與實作
因為題目給的是兩個有序的鏈結串列,所以這題只須兩個指針分別指向給定的陣列,將節點值較小的添加到新的鏈結串列,添加完後將指標移往下一個節點,直到兩鏈結串列的節點都被添加到新的鏈結串列為止。
1 |
|