diff options
Diffstat (limited to 'Computer_Science')
| -rw-r--r-- | Computer_Science/leetcode/61-rotate_list.c | 39 | ||||
| -rwxr-xr-x | Computer_Science/leetcode/61-rotate_list.c.out | bin | 0 -> 8152 bytes | |||
| -rw-r--r-- | Computer_Science/leetcode/61-rotate_list.c~ | 0 | ||||
| -rw-r--r-- | Computer_Science/leetcode/82-remove_duplicates_from_sorted_list_II.c | 50 | ||||
| -rw-r--r-- | Computer_Science/leetcode/82-remove_duplicates_from_sorted_list_II.c~ | 17 | ||||
| -rw-r--r-- | Computer_Science/leetcode/83-remove_duplicates_from_sorted_list.c | 34 | ||||
| -rw-r--r-- | Computer_Science/leetcode/83-remove_duplicates_from_sorted_list.c~ | 10 | ||||
| -rw-r--r-- | Computer_Science/leetcode/86-partition_list.c | 52 | ||||
| -rw-r--r-- | Computer_Science/leetcode/86-partition_list.c~ | 27 |
9 files changed, 229 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() +{ +} diff --git a/Computer_Science/leetcode/61-rotate_list.c.out b/Computer_Science/leetcode/61-rotate_list.c.out Binary files differnew file mode 100755 index 0000000..8f84219 --- /dev/null +++ b/Computer_Science/leetcode/61-rotate_list.c.out diff --git a/Computer_Science/leetcode/61-rotate_list.c~ b/Computer_Science/leetcode/61-rotate_list.c~ new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Computer_Science/leetcode/61-rotate_list.c~ diff --git a/Computer_Science/leetcode/82-remove_duplicates_from_sorted_list_II.c b/Computer_Science/leetcode/82-remove_duplicates_from_sorted_list_II.c new file mode 100644 index 0000000..259a829 --- /dev/null +++ b/Computer_Science/leetcode/82-remove_duplicates_from_sorted_list_II.c @@ -0,0 +1,50 @@ +#include <stdio.h> + +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * struct ListNode *next; + * }; + */ + +struct ListNode { + int val; + struct ListNode *next; +}; + +struct ListNode* deleteDuplicates(struct ListNode* head) { + struct ListNode *p = head; + struct ListNode *prev = p; + + if(p == NULL) return head; + + while(p->next != NULL) { + if(p->val == p->next->val) + ; + else { + if(head != p && head->val == p->val) { + head = p->next; + prev = p->next; + } else { + if(prev->next == p) + prev = p; + prev->next = p->next; + } + } + p = p->next; + } + + if(head != p && head->val == p->val) + return NULL; + + if(prev->next != p) + prev->next = NULL; + + return head; +} + +int main() +{ + return 0; +} diff --git a/Computer_Science/leetcode/82-remove_duplicates_from_sorted_list_II.c~ b/Computer_Science/leetcode/82-remove_duplicates_from_sorted_list_II.c~ new file mode 100644 index 0000000..4b0fbe2 --- /dev/null +++ b/Computer_Science/leetcode/82-remove_duplicates_from_sorted_list_II.c~ @@ -0,0 +1,17 @@ +#include <stdio.h> + +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * struct ListNode *next; + * }; + */ + +struct ListNode { + int val; + struct ListNode *next; +}; +struct ListNode* deleteDuplicates(struct ListNode* head) { + +} diff --git a/Computer_Science/leetcode/83-remove_duplicates_from_sorted_list.c b/Computer_Science/leetcode/83-remove_duplicates_from_sorted_list.c new file mode 100644 index 0000000..44be83f --- /dev/null +++ b/Computer_Science/leetcode/83-remove_duplicates_from_sorted_list.c @@ -0,0 +1,34 @@ +#include <stdio.h> + +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * struct ListNode *next; + * }; + */ +struct ListNode { + int val; + struct ListNode *next; +}; + +struct ListNode* deleteDuplicates(struct ListNode* head) { + struct ListNode *p = head; + struct ListNode *prev = p; + + if(head == NULL) return head; + + while(p->next != NULL) { + if(p->val == p->next->val) + ; + else { + prev->next = p->next; + prev = p->next; + } + p = p->next; + } + + prev->next = NULL; + + return head; +} diff --git a/Computer_Science/leetcode/83-remove_duplicates_from_sorted_list.c~ b/Computer_Science/leetcode/83-remove_duplicates_from_sorted_list.c~ new file mode 100644 index 0000000..82988fe --- /dev/null +++ b/Computer_Science/leetcode/83-remove_duplicates_from_sorted_list.c~ @@ -0,0 +1,10 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * struct ListNode *next; + * }; + */ +struct ListNode* deleteDuplicates(struct ListNode* head) { + +} diff --git a/Computer_Science/leetcode/86-partition_list.c b/Computer_Science/leetcode/86-partition_list.c new file mode 100644 index 0000000..0deceb8 --- /dev/null +++ b/Computer_Science/leetcode/86-partition_list.c @@ -0,0 +1,52 @@ +#include <stdio.h> +#include <stdlib.h> + +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * struct ListNode *next; + * }; + */ +struct ListNode { + int val; + struct ListNode *next; +}; +struct ListNode* partition(struct ListNode* head, int x) { + struct ListNode *hl = NULL; + struct ListNode *tl = NULL; + struct ListNode *hg = NULL; + struct ListNode *tg = NULL; + struct ListNode *tmp; + + if(head == NULL) return head; + + for(; head != NULL; head = head->next) { + tmp = malloc(sizeof(struct ListNode)); + tmp->val = head->val; + tmp->next = NULL; + if(head->val < x) { + if(tl == NULL) + hl = tl = tmp; + else { + tl->next = tmp; + tl = tl->next; + } + } + else { + if(tg == NULL) + hg = tg = tmp; + else { + tg->next = tmp; + tg = tg->next; + } + } + } + + if(hl != NULL) { + tl->next = hg; + } else + return hg; + + return hl; +} diff --git a/Computer_Science/leetcode/86-partition_list.c~ b/Computer_Science/leetcode/86-partition_list.c~ new file mode 100644 index 0000000..98ef6bf --- /dev/null +++ b/Computer_Science/leetcode/86-partition_list.c~ @@ -0,0 +1,27 @@ +#include <stdio.h> + +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * struct ListNode *next; + * }; + */ +struct ListNode { + int val; + struct ListNode *next; +}; +struct ListNode* partition(struct ListNode* head, int x) { + struct ListNode *h; + struct ListNode *hl; + struct ListNode *hg; + + for(; head != NULL; head = head->next) { + if(head->val < x) + ; + else + ; + } + + +} |
