问题描述:
代码:
class Solution {
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
ListNode newR=new ListNode(-1);
ListNode newR2=newR;
while(l1!=null&&l2!=null){
if(l1.val<=l2.val){
newR2.next=l1;
l1=l1.next;
}else{
newR2.next=l2;
l2=l2.next;
}
newR2=newR2.next;
}
if(l1!=null){
newR2.next=l1;
}
if(l2!=null){
newR2.next=l2;
}
return newR.next;
}
}
思路:
问题描述:
代码:
class Solution {
public ListNode reverseList(ListNode head) {
ListNode newList = null;
ListNode newList2= head;
while(newList2!=null){
ListNode next = newList2.next;
newList2.next=newList;
newList=newList2;
newList2=next;
}
return newList;
}
}
思路: