题目:
题解:
func reverseKGroup(head *ListNode, k int) *ListNode {hair := &ListNode{Next: head}pre := hairfor head != nil {tail := prefor i := 0; i < k; i++ {tail = tail.Nextif tail == nil {return hair.Next}}nex := tail.Nexthead, tail = myReverse(head, tail)pre.Next = headtail.Next = nexpre = tailhead = tail.Next}return hair.Next
}func myReverse(head, tail *ListNode) (*ListNode, *ListNode) {prev := tail.Nextp := headfor prev != tail {nex := p.Nextp.Next = prevprev = pp = nex}return tail, head
}