LintCode之35 翻转链表

题目来源:翻转链表

题目描述:
翻转一个链表

样例:
给出一个链表1->2->3->null,这个翻转后的链表为3->2->1->null

Java代码:

public ListNode reverse(ListNode head) {
        // write your code here
        int count=0;
        int[] xulie = new int[1000];
        ListNode listNode = head;
        while (listNode!=null) {
            xulie[count] = listNode.val;
            listNode = listNode.next;
            count++;
        }
        count--;
        listNode = head;
        while (listNode!=null) {
            listNode.val = xulie[count];
            count--;
            listNode = listNode.next;
        }
        return head;
    }

你可能感兴趣的:(LintCode刷题)