94. 二叉树的中序遍历


 

给定一个二叉树,返回它的中序 遍历。

示例:

输入: [1,null,2,3]
   1
    \
     2
    /
   3

输出: [1,3,2]
vector<int > res;
vector<int> inorderTraversal(TreeNode* root) {

    f(root);
    
    /*if (root == NULL)
        return;
    inorderTraversal(root->left);
    res.push_back(root->val);
    inorderTraversal(root->right);*/
    return res;
}
void f(TreeNode* root)
{
    if (root == NULL)
        return;
    inorderTraversal(root->left);
    res.push_back(root->val);
    inorderTraversal(root->right);

}

 

posted @ 2018-10-28 21:23  Binary_tony  阅读(96)  评论(0编辑  收藏  举报