This commit is contained in:
2025-09-15 21:12:04 +08:00
commit 3f58f483ff
144 changed files with 5298 additions and 0 deletions

58
else/topic/2024.h Normal file
View File

@@ -0,0 +1,58 @@
//
// Created by 李洋 on 2023/12/21.
//
#ifndef LEECODE_C_2024_H
#define LEECODE_C_2024_H
#include "stack"
struct Node {
int value;
struct Node *left;
struct Node *right;
bool tag1;
bool tag2;
};
using namespace std;
int calculate(stack<Node *> S) {
stack<Node *> temp;
int num = 0;
int i = 0;
while (!S.empty()) {
num += S.top()->value * pow(10, i++);
S.pop();
}
return num;
}
int get(Node *root) {
if (!root) {
return 0;
}
int count = 0;
stack<Node *> S;
S.push(root);
while (!S.empty()) {
if (!S.top()->left && !S.top()->right) {
count += calculate(S);
}
if (S.top()->tag1 == 0 && S.top()->left) {
S.top()->tag1 = 1;
S.push(S.top()->left);
continue;
}
if (S.top()->tag2 == 0 && S.top()->left) {
S.top()->tag2 = 1;
S.push(S.top()->right);
continue;
}
S.pop();
}
return count;
}
#endif //LEECODE_C_2024_H