(206)-(Reverse Linked List)-(反序输出单链表)-(注意,用头插法)

(206)-(Reverse Linked List)-(???????)-(??,????)

public class Solution 
{
  public ListNode reverseList(ListNode head) 
    {
        if(head==null ||head.next==null)  //0ИіЛђеп1Иі
        {
            return head;
        }
        ListNode final_ans=new ListNode(0);
        ListNode r_ans;
        
        while(head!=null)
        {    
            r_ans = final_ans.next;
            ListNode temp=new ListNode(head.val);
            final_ans.next=temp;
            temp.next=r_ans;
            
            head=head.next;
        }
        return final_ans.next;
    }
}

 

posted @ 2015-07-25 20:07  爱吃萝卜干  阅读(129)  评论(0编辑  收藏  举报