解题思路:
(1)递归求解
/**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int val) {
* this->val = val;
* this->left = this->right = NULL;
* }
* }
*/
class Solution {
public:
/**
* @param root: A Tree
* @return: Inorder in ArrayList which contains node values.
*/
vector<int> v;
vector<int> inorderTraversal(TreeNode * root) {
// write your code here
inorder(root);
return v;
}
void inorder(TreeNode *root) {
if (root) {
inorder(root->left);
v.push_back(root->val);
inorder(root->right);
}
}
};