94. Binary Tree Inorder Traversal(Tree)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tangyuanzong/article/details/80063081

https://leetcode.com/problems/binary-tree-inorder-traversal/description/

题目:求二叉树的中序遍历

思路:直接中序遍历。

class Solution {
public:
    vector<int>v;
    void inorder(TreeNode *root){
         if(!root) return ;
         inorder(root->left);
         v.push_back(root->val);
         inorder(root->right);
    }
    vector<int> inorderTraversal(TreeNode* root) {
          inorder(root);
          return v;
    }
};

猜你喜欢

转载自blog.csdn.net/tangyuanzong/article/details/80063081