题目:Merge Two Sorted Lists
难度:easy
问题描述:
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.
将两个已经排列好的链表整合成一个新的排列好的链表。
解题思路:很简单的一道题···没啥好说的,注意边界就好哈。
代码如下:
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
if(l1==null&&l2==null) return null;
if(l1==null) return l2;
if(l2==null) return l1;
ListNode head,temp;
ListNode p1=l1,p2=l2;
if(p1.val