feat: LeetCode Next Greater Node In Linked List solution (1019) (#1022)

Co-authored-by: David Leal <halfpacho@gmail.com>
This commit is contained in:
Sindhu Inti 2022-11-02 11:44:45 +05:30 committed by GitHub
parent 27145d7ce4
commit 9ab1bc981b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -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 |

29
leetcode/src/1019.c Normal file
View File

@ -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;
}