255.LeetCode | 94. 二叉树的中序遍历
每天一个开发小知识
01
/**
* 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 Solution {
public:
vector<int> inorderTraversal(TreeNode* root) {
vector<int> ret;
Do(root, ret);
return ret;
}
void Do(TreeNode * node, vector<int> & ret) {
if (NULL == node)
{
return;
}
Do(node->left, ret);
ret.push_back(node->val);
Do(node->right, ret);
}
};