与数组合并一样
合并k个已排序的链表
http://www.nowcoder.com/questionTerminal/65cfde9e5b9b4cf2b6bafa5f3ef33fa6
public class Solution { /** * * @param l1 ListNode类 * @param l2 ListNode类 * @return ListNode类 */ public ListNode mergeTwoLists (ListNode l1, ListNode l2) { // write code here+ ListNode head=new ListNode(0); ListNode p=head; while(l1!=null&&l2!=null) { if(l1.val<l2.val) { p.next=l1; p=p.next; l1=l1.next; }else { p.next=l2; p=p.next; l2=l2.next; } } if(l1!=null) { p.next=l1; }else { p.next=l2; } return head.next; } }