From 3f521a9849997608712e92ad8e90e83ff1cefdc0 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Mon, 25 Aug 2025 13:06:21 -0600 Subject: chore: Tidy util files and add listnode_build Removes unnecessary C++ specific header file code Adds C and Python helper functions to build a full ListNode based on an integer array as input --- leetcode.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'leetcode.c') diff --git a/leetcode.c b/leetcode.c index b6fe769..b7c3b22 100644 --- a/leetcode.c +++ b/leetcode.c @@ -27,6 +27,17 @@ struct ListNode *listnode_create(int val) { return new; } +struct ListNode *listnode_build(int *vals, int size) { + if (!size) + return NULL; + struct ListNode *head = listnode_create(vals[0]), *curr = head; + for (int i = 1; i < size; i++) { + curr->next = listnode_create(vals[i]); + curr = curr->next; + } + return head; +} + void listnode_print(struct ListNode *head) { struct ListNode *curr = head; while (curr != NULL) { -- cgit v1.2.3