1
0

2022.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "../structs/List.h"
  2. #include <vector>
  3. using namespace std;
  4. vector<vector<int>> test1(ListNode *head)
  5. {
  6. vector<vector<int>> ret;
  7. int prev = head->value;
  8. int index = 0;
  9. ret.push_back(vector<int>(1, prev));
  10. ListNode *temp = head->next;
  11. while (!temp)
  12. {
  13. if (prev == temp->value)
  14. {
  15. index++;
  16. }
  17. else
  18. {
  19. index = 0;
  20. }
  21. if (index >= ret.size())
  22. {
  23. ret.push_back(vector<int>(1, temp->value));
  24. }
  25. if (index < ret.size())
  26. {
  27. ret[index].push_back(temp->value);
  28. }
  29. temp = temp->next;
  30. }
  31. return ret;
  32. }
  33. #include "../structs/Tree.h"
  34. pair<bool, int> help(TreeNode *root)
  35. {
  36. if (!root)
  37. {
  38. return {true, 0};
  39. }
  40. auto p1 = help(root->left);
  41. auto p2 = help(root->right);
  42. if (!p1.first || !p2.first)
  43. {
  44. return {false, 0};
  45. }
  46. if (abs(p1.second - p2.second) > 1)
  47. {
  48. return {false, 0};
  49. }
  50. return {true, max(p1.second, p2.second) + 1};
  51. }
  52. bool test2(TreeNode *root)
  53. {
  54. return help(root).first;
  55. }
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。