1. 程式人生 > >94. Binary Tree Inorder Traversal(Tree)

94. Binary Tree Inorder Traversal(Tree)

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; } };