三序遍历
实现二叉树先序,中序和后序遍历
https://www.nowcoder.com/practice/a9fec6c46a684ad5a3abd4e365a9d362?tpId=117&&tqId=37819&&companyId=239&rp=1&ru=/company/home/code/239&qru=/ta/job-code-high/question-ranking
//题目自动给的代码还真不能删
/**
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
class Solution {
public:
/**
*
* @param root TreeNode类 the root of binary tree
* @return int整型vector<vector<>>
*/
void threeOrders(TreeNode* root, vector<vector<int> > &vect){
if(!root)
return;
vect[0].push_back(root->val);
threeOrders(root->left,vect);
vect[1].push_back(root->val);
threeOrders(root->right,vect);
vect[2].push_back(root->val);
}
vector<vector<int> > vect = {{},{},{}};
vector<vector<int> > threeOrders(TreeNode* root) {
// write code here
threeOrders(root,vect); //貌似用了重载
return vect;
}
};