From 25b4f2abd597ffba22cccea8587d00540577197d Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 15 Dec 2017 09:37:26 +0800 Subject: add some solution --- Computer_Science/leetcode/61-rotate_list.c | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Computer_Science/leetcode/61-rotate_list.c (limited to 'Computer_Science/leetcode/61-rotate_list.c') diff --git a/Computer_Science/leetcode/61-rotate_list.c b/Computer_Science/leetcode/61-rotate_list.c new file mode 100644 index 0000000..8cbbe17 --- /dev/null +++ b/Computer_Science/leetcode/61-rotate_list.c @@ -0,0 +1,39 @@ +#include + +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * struct ListNode *next; + * }; + */ + +struct ListNode { + int val; + struct ListNode *next; +}; + +struct ListNode* rotateRight(struct ListNode* head, int k) +{ + int i; + int length = 1; + struct ListNode* p = head; + + if(p == NULL) return head; + + for(; p->next != NULL; p = p->next) + length++; + + p->next = head; + + for(i = 0; i < length - k % length; i++) + p = p->next; + head = p->next; + p->next = NULL; + + return head; +} + +int main() +{ +} -- cgit v1.2.3