Rotate List
2014-03-08 14:13
162 查看
class Solution { public: ListNode *rotateRight(ListNode *head, int k) { if(head==NULL) return NULL; ListNode *p,*q,*qpre,*end; q=p=head; int count=0; while(p!=NULL) { if(p->next==NULL) end=p; p=p->next; count++; } if(k>=count) k=(k-count)%count; if(count-k==0||k==0) return head; for(int i=1;i<=count-k;i++) { qpre=q; q=q->next; } qpre->next=NULL; end->next=head; return q; } };不停地传,不停地错,写得乱七八糟
相关文章推荐
- 【leetcode】Rotate List
- Rotate List
- Rotate List
- Rotate List
- [LeetCode] Rotate List
- Rotate List
- Rotate List - LeetCode 62
- Rotate List
- 《leetCode》:Rotate List
- leetcode 061 Rotate List
- LeetCode61 Rotate List
- 61. Rotate List
- LeetCode | 61. Rotate List
- LeetCode(61)——Rotate List
- LeetCode: Rotate List
- Rotate List
- [leetcode]Rotate List
- Rotate List
- leetcode--Rotate List
- leetcode_61_Rotate List