1. 程式人生 > >lintcode——二叉樹的中序遍歷

lintcode——二叉樹的中序遍歷

/**
 * Definition of TreeNode:
 * class TreeNode {
 * public:
 *     int val;
 *     TreeNode *left, *right;
 *     TreeNode(int val) {
 *         this->val = val;
 *         this->left = this->right = NULL;
 *     }
 * }
 */
class Solution {
    /**
     * @param root: The root of binary tree.
     * @return: Inorder in vector which contains node values.
     */
public:
    std::vector<int> t;
    vector<int> inorderTraversal(TreeNode *root) {
        // write your code here
    if(root==NULL) return t;
    else{
        inorderTraversal(root->left);
        t.push_back(root->val);
        inorderTraversal(root->right);
      }
      return t;
    }
};