Go语言中文网 为您找到相关结果 1

leetcode_61

Golang: 思路:先得出链表长度,然后就可以对k做处理,打个比方,链表长度5,那么k=6与k=1的情况就是一致的,但是我最后代码写的还是很复杂,不做参考吧。 代码如下: func rotateRight(head *ListNode, k int) *ListNode { if k==0||head==nil||head.Next==nil { return head } length,temp:=0,head for temp.Next!=nil{ temp=temp.Next length++ } length++ var res *ListNode last,i:=temp,0 temp=head k=k%length if k==0 { return head }else { l...阅读全文

博文 2020-02-04 19:33:06 淳属虚构