File tree 2 files changed +49
-0
lines changed
2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ You can build all the files using `make` (Use MinGW GCC and GNU Make on Windows)
24
24
25
25
| | Problem | Solution |
26
26
| --- | ------------------------------------------------------------ | ------------------ |
27
+ | 237 | [ Delete Node in a Linked List] | [ C] ( src/237.c ) |
28
+ | 236 | [ Lowest Common Ancestor of a Binary Tree] | |
27
29
| 235 | [ Lowest Common Ancestor of a Binary Search Tree] | [ C] ( src/235.c ) |
28
30
| 234 | [ Palindrome Linked List] | [ C] ( src/234.c ) |
29
31
| 233 | [ Number of Digit One] | |
@@ -248,6 +250,8 @@ You can build all the files using `make` (Use MinGW GCC and GNU Make on Windows)
248
250
[ LeetCode algorithm problems ] : https://leetcode.com/problemset/algorithms/
249
251
250
252
253
+ [ Delete Node in a Linked List ] : https://leetcode.com/problems/delete-node-in-a-linked-list/
254
+ [ Lowest Common Ancestor of a Binary Tree ] : https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/
251
255
[ Lowest Common Ancestor of a Binary Search Tree ] : https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/
252
256
[ Palindrome Linked List ] : https://leetcode.com/problems/palindrome-linked-list/
253
257
[ Number of Digit One ] : https://leetcode.com/problems/number-of-digit-one/
Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+
4
+ struct ListNode {
5
+ int val ;
6
+ struct ListNode * next ;
7
+ };
8
+
9
+ void deleteNode (struct ListNode * node ) {
10
+ if (node == NULL || node -> next == NULL ) return ;
11
+
12
+ node -> val = node -> next -> val ;
13
+ node -> next = node -> next -> next ;
14
+ }
15
+
16
+ void printList (struct ListNode * head ) {
17
+ while (head ) {
18
+ printf ("%d->" , head -> val );
19
+ head = head -> next ;
20
+ }
21
+ printf ("N\n" );
22
+ }
23
+
24
+ int main () {
25
+
26
+ struct ListNode * l1 = (struct ListNode * )calloc (3 , sizeof (struct ListNode ));
27
+
28
+ l1 -> val = 1 ;
29
+ l1 -> next = l1 + 1 ;
30
+
31
+ l1 -> next -> val = 2 ;
32
+ l1 -> next -> next = l1 + 2 ;
33
+
34
+ l1 -> next -> next -> val = 3 ;
35
+ l1 -> next -> next -> next = NULL ;
36
+
37
+ printList (l1 );
38
+
39
+ /* delete 2 */
40
+ deleteNode (l1 -> next );
41
+
42
+ printList (l1 );
43
+
44
+ return 0 ;
45
+ }
You can’t perform that action at this time.
0 commit comments