funcReserveList(head *ListNode) *ListNode { if head == nil || head.next == nil { return head } var pre *ListNode for head != nil { // 简化版: // head, head.next, pre = head.next, pre, head nextNode := head.next head.next = pre pre = head head = nextNode } return pre }
funcReserveList(head *ListNode) *ListNode { if head == nil || head.next == nil { return head } cur := head for head.next != nil { tmp := head.next.next head.next.next = cur cur = head.next head.next = tmp } return cur }