diff --git a/problems/0203.移除链表元素.md b/problems/0203.移除链表元素.md index cac9f233..ea1d705a 100644 --- a/problems/0203.移除链表元素.md +++ b/problems/0203.移除链表元素.md @@ -146,8 +146,39 @@ public: ## 其他语言版本 +C: +```c +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * struct ListNode *next; + * }; + */ +struct ListNode* removeElements(struct ListNode* head, int val){ + typedef struct ListNode ListNode; + ListNode *shead; + shead = (ListNode *)malloc(sizeof(ListNode)); + shead->next = head; + ListNode *cur = shead; + while(cur->next != NULL){ + if (cur->next->val == val){ + ListNode *tmp = cur->next; + cur->next = cur->next->next; + free(tmp); + } + else{ + cur = cur->next; + } + } + head = shead->next; + free(shead); + return head; +} +``` + Java: ```java /**