美文网首页
206. Reverse Linked List

206. Reverse Linked List

作者: 夜皇雪 | 来源:发表于2016-12-13 05:38 被阅读0次
    /**
     * Definition for singly-linked list.
     * public class ListNode {
     *     int val;
     *     ListNode next;
     *     ListNode(int x) { val = x; }
     * }
     */
    public class Solution {
        public ListNode reverseList(ListNode head) {
            ListNode pre=null;
            while(head!=null){
                ListNode tmp=head.next;
                head.next=pre;
                pre=head;
                head=tmp;
            }
            return pre;
        }
    }
    

    相关文章

      网友评论

          本文标题:206. Reverse Linked List

          本文链接:https://www.haomeiwen.com/subject/epuvmttx.html