Java solution 0ms 用头节点倒插


  • 7
    M
    public static ListNode reverseList(ListNode head) {
    		ListNode result = new ListNode(0);
    		ListNode p = null;
    		while (head != null) {
    			p = head;
    			head = head.next;
    			p.next = result.next;
    			result.next = p;
    		}
            return result.next;
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.