-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
42 lines (39 loc) · 814 Bytes
/
test.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
void findDuplicates(int arr[], int n) {
int i, j;
printf(
);
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if (arr[i] == arr[j]) {
printf(
, arr[i]);
}
}
}
}
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode *removeNthFromEnd(struct ListNode *head, int n) {
struct ListNode entry, *p_free, *p = head;
int i, sz = 0;
entry.next = head;
while (p != NULL) {
p = p->next;
sz++;
}
for (i = 0, p = &entry; i < sz - n; i++, p = p -> next)
;
p_free = p->next;
if (n != 1) {
p->next = p->next->next;
} else {
p->next = NULL;
}
free(p_free);
return entry.next;
}