aboutsummaryrefslogtreecommitdiff
path: root/leetcode.c
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-08-25 13:06:21 -0600
committerJack Sangdahl <[email protected]>2025-08-25 13:06:21 -0600
commit3f521a9849997608712e92ad8e90e83ff1cefdc0 (patch)
tree7b8224a755318088a78d30c7bb2ddfa9e2473bae /leetcode.c
parent07c9e6547189b072d990fb861194449cdc14f5c5 (diff)
downloadleetcode-3f521a9849997608712e92ad8e90e83ff1cefdc0.tar.gz
leetcode-3f521a9849997608712e92ad8e90e83ff1cefdc0.zip
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
Diffstat (limited to 'leetcode.c')
-rw-r--r--leetcode.c11
1 files changed, 11 insertions, 0 deletions
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) {