aboutsummaryrefslogtreecommitdiff
path: root/Computer_Science/leetcode/61-rotate_list.c
diff options
context:
space:
mode:
authorSteve Lee <me@xiangyangli.com>2017-12-15 09:37:26 +0800
committerSteve Lee <me@xiangyangli.com>2017-12-15 09:37:26 +0800
commit25b4f2abd597ffba22cccea8587d00540577197d (patch)
tree6f196e6b6f89da6aebc80170324684d7dcc1adf7 /Computer_Science/leetcode/61-rotate_list.c
parentb9659f0ae3b4766cccea4f6f62d883cd61f98620 (diff)
download42-25b4f2abd597ffba22cccea8587d00540577197d.tar.xz
42-25b4f2abd597ffba22cccea8587d00540577197d.zip
add some solution
Diffstat (limited to 'Computer_Science/leetcode/61-rotate_list.c')
-rw-r--r--Computer_Science/leetcode/61-rotate_list.c39
1 files changed, 39 insertions, 0 deletions
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 <stdio.h>
+
+/**
+ * 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()
+{
+}