mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
feat: LeetCode Next Greater Node In Linked List solution (1019) (#1022)
Co-authored-by: David Leal <halfpacho@gmail.com>
This commit is contained in:
parent
27145d7ce4
commit
9ab1bc981b
@ -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
29
leetcode/src/1019.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user