61. Rotate List
2017-02-02 03:55
106 查看
题意简单,但是但是!!!!
超级多小细节,一定要二刷!!!!
练手好体!!!
超级多小细节,一定要二刷!!!!
练手好体!!!
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* rotateRight(ListNode* head, int k) { int n = 1; if(head == NULL || head -> next == NULL) return head; ListNode* t; ListNode* u; ListNode* newhead; for(t = head; t -> next != NULL; t = t -> next) n++; if(n == k) return head; k = k % n; if(k == 0) return head; t = head; for(int i = 1; i < n - k; ++ i) t = t -> next; u = t -> next; newhead = u; t -> next = NULL; while(u -> next != NULL) u = u -> next; u -> next = head; return newhead; } };
相关文章推荐
- LeetCode 61. Rotate List
- leetcode 61.Rotate List
- (Java)LeetCode-61. Rotate List
- 61. Rotate List
- 61-Rotate list
- 61. Rotate List
- 61 Rotate List
- 61. Rotate List
- leetcode 61.Rotate List
- leetcode - 61.Rotate List
- 61. Rotate List
- 【Leetcode】61. Rotate List
- [Leetcode]@python 61. Rotate List
- Leetcode ☞ 61. Rotate List
- LeetCode 61: Rotate List
- leetcode-61. Rotate List
- [leetcode]61. Rotate List
- 【leetcode每日一题】61.Rotate List
- [LeetCode61]Rotate List
- leetcode61: Rotate List