Merge pull request #525 from bdzyq/master

C实现
This commit is contained in:
程序员Carl
2021-07-29 10:26:55 +08:00
committed by GitHub

View File

@ -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
/**