1
0

2024.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Created by 李洋 on 2023/12/21.
  3. //
  4. #ifndef LEECODE_C_2024_H
  5. #define LEECODE_C_2024_H
  6. #include "stack"
  7. struct Node {
  8. int value;
  9. struct Node *left;
  10. struct Node *right;
  11. bool tag1;
  12. bool tag2;
  13. };
  14. using namespace std;
  15. int calculate(stack<Node *> S) {
  16. stack<Node *> temp;
  17. int num = 0;
  18. int i = 0;
  19. while (!S.empty()) {
  20. num += S.top()->value * pow(10, i++);
  21. S.pop();
  22. }
  23. return num;
  24. }
  25. int get(Node *root) {
  26. if (!root) {
  27. return 0;
  28. }
  29. int count = 0;
  30. stack<Node *> S;
  31. S.push(root);
  32. while (!S.empty()) {
  33. if (!S.top()->left && !S.top()->right) {
  34. count += calculate(S);
  35. }
  36. if (S.top()->tag1 == 0 && S.top()->left) {
  37. S.top()->tag1 = 1;
  38. S.push(S.top()->left);
  39. continue;
  40. }
  41. if (S.top()->tag2 == 0 && S.top()->left) {
  42. S.top()->tag2 = 1;
  43. S.push(S.top()->right);
  44. continue;
  45. }
  46. S.pop();
  47. }
  48. return count;
  49. }
  50. #endif //LEECODE_C_2024_H
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。