mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
@ -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:
|
||||||
```java
|
```java
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user