题目:
题解:
func rotateRight(head *ListNode, k int) *ListNode {if k == 0 || head == nil || head.Next == nil {return head}n := 1iter := headfor iter.Next != nil {iter = iter.Nextn++}add := n - k%nif add == n {return head}iter.Next = headfor add > 0 {iter = iter.Nextadd--}ret := iter.Nextiter.Next = nilreturn ret
}