forked from lennylxx/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
237.c
45 lines (32 loc) · 816 Bytes
/
237.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
struct ListNode {
int val;
struct ListNode *next;
};
void deleteNode(struct ListNode* node) {
if (node == NULL || node->next == NULL) return;
node->val = node->next->val;
node->next = node->next->next;
}
void printList(struct ListNode* head) {
while (head) {
printf("%d->", head->val);
head = head->next;
}
printf("N\n");
}
int main() {
struct ListNode *l1 = (struct ListNode *)calloc(3, sizeof(struct ListNode));
l1->val = 1;
l1->next = l1 + 1;
l1->next->val = 2;
l1->next->next = l1 + 2;
l1->next->next->val = 3;
l1->next->next->next = NULL;
printList(l1);
/* delete 2 */
deleteNode(l1->next);
printList(l1);
return 0;
}