-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution105.hpp
More file actions
39 lines (34 loc) · 896 Bytes
/
Solution105.hpp
File metadata and controls
39 lines (34 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// Solution105.hpp
// Algorithm
//
// Created by Pancf on 2020/12/6.
// Copyright © 2020 Pancf. All rights reserved.
//
#ifndef Solution105_hpp
#define Solution105_hpp
#include <stdio.h>
#include <vector>
/**
* Definition for a binary tree node.
*/
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode() : val(0), left(nullptr), right(nullptr) {}
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};
class Solution105 {
public:
TreeNode* buildTree(std::vector<int>& preorder, std::vector<int>& inorder);
static void test()
{
std::vector<int> preorder{3,9,20,15,7};
std::vector<int> inorder{9,3,15,20,7};
Solution105 s;
auto root = s.buildTree(preorder, inorder);
}
};
#endif /* Solution105_hpp */