1
0

590.h 774 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // Created by 李洋 on 2024/2/19.
  3. //
  4. #ifndef LEETCODE_C_590_H
  5. #define LEETCODE_C_590_H
  6. #include <stdlib.h>
  7. struct Node {
  8. int val;
  9. int numChildren;
  10. struct Node **children;
  11. };
  12. /**
  13. * Note: The returned array must be malloced, assume caller calls free().
  14. */
  15. #define MAX_NODE_SIZE 10000
  16. void helper(const struct Node* root, int* res, int* pos) {
  17. if (NULL == root) {
  18. return;
  19. }
  20. for (int i = 0; i < root->numChildren; i++) {
  21. helper(root->children[i], res, pos);
  22. }
  23. res[(*pos)++] = root->val;
  24. }
  25. int* postorder(struct Node* root, int* returnSize) {
  26. int * res = (int *)malloc(sizeof(int) * MAX_NODE_SIZE);
  27. int pos = 0;
  28. helper(root, res, &pos);
  29. *returnSize = pos;
  30. return res;
  31. }
  32. #endif //LEETCODE_C_590_H
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。