From 9ab1bc981bf3cc34cbc7bcdd4a21fe0f95c13986 Mon Sep 17 00:00:00 2001 From: Sindhu Inti <89198083+Sindhuinti@users.noreply.github.com> Date: Wed, 2 Nov 2022 11:44:45 +0530 Subject: [PATCH] feat: LeetCode Next Greater Node In Linked List solution (1019) (#1022) Co-authored-by: David Leal --- leetcode/README.md | 3 ++- leetcode/src/1019.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 leetcode/src/1019.c diff --git a/leetcode/README.md b/leetcode/README.md index c1223384..60319643 100644 --- a/leetcode/README.md +++ b/leetcode/README.md @@ -90,8 +90,9 @@ | 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst/) | [C](./src/938.c) | Easy | | 965 | [Univalued Binary Tree](https://leetcode.com/problems/univalued-binary-tree/) | [C](./src/965.c) | Easy | | 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array/) | [C](./src/977.c) | Easy | +| 1019 | [Next Greater Node In Linked List](https://leetcode.com/problems/next-greater-node-in-linked-list/) | [C](./src/1019.c) | Medium | | 1089 | [Duplicate Zeros](https://leetcode.com/problems/duplicate-zeros/) | [C](./src/1089.c) | Easy | | 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops/) | [C](./src/1184.c) | Easy | | 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons/) | [C](./src/1189.c) | Easy | | 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences/) | [C](./src/1207.c) | Easy | -| 2130 | [Maximum Twin Sum of a Linked List](https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list/) | [C](./src/2130.c) | Medium | +| 2130 | [Maximum Twin Sum of a Linked List](https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list/) | [C](./src/2130.c) | Medium | \ No newline at end of file diff --git a/leetcode/src/1019.c b/leetcode/src/1019.c new file mode 100644 index 00000000..31eca53d --- /dev/null +++ b/leetcode/src/1019.c @@ -0,0 +1,29 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * struct ListNode *next; + * }; + */ + +int* nextLargerNodes(struct ListNode* head, int* returnSize) +{ + int *output, count = 0; + struct ListNode *tmp = head, *tmp2; + for (; tmp != NULL; tmp = tmp->next, count++) + ; + output = (int*)calloc(count, sizeof(int)); + *returnSize = count; + for (tmp = head, count = 0; tmp->next != NULL; tmp = tmp->next, count++) + { + for (tmp2 = tmp->next; tmp2 != NULL; tmp2 = tmp2->next) + { + if (tmp2->val > tmp->val) + { + output[count] = tmp2->val; + break; + } + } + } + return output; +}