1
0

1019.c 960 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. struct ListNode
  2. {
  3. int val;
  4. struct ListNode *next;
  5. };
  6. typedef struct Pair {
  7. int first;
  8. int second;
  9. } Pair;
  10. int getLength(struct ListNode* head){
  11. int len = 0;
  12. ListNode* node = head;
  13. while (node.next)
  14. {
  15. node = node.next;
  16. len++;
  17. }
  18. return len;
  19. }
  20. int* nextLargerNodes(struct ListNode* head, int* returnSize){
  21. int len = 0;
  22. struct ListNode* cur = head;
  23. while (cur) {
  24. cur = cur->next;
  25. len++;
  26. }
  27. int* ans = (int *)calloc(len, sizeof(int));
  28. Pair stack[len];
  29. int top = 0, pos = 0;
  30. cur = head;
  31. int idx = -1;
  32. while (cur) {
  33. ++idx;
  34. ans[pos++] = 0;
  35. while (top > 0 && stack[top - 1].first < cur->val) {
  36. ans[stack[top - 1].second] = cur->val;
  37. top--;
  38. }
  39. stack[top].first = cur->val;
  40. stack[top].second = idx;
  41. top++;
  42. cur = cur->next;
  43. }
  44. *returnSize = len;
  45. return ans;
  46. }
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。