-----QUESTION-----
Given a binary tree, return the
For example:
Given binary tree {1,#,2,3}
,
1 \ 2 / 3
return [1,3,2]
.
Note:
-----SOLUTION-----]
class Solution {
public:
vector<int> inorderTraversal(TreeNode *root) {
result.clear();
if (!root) return result;
inorderHelper(root);
return result;
}
void inorderHelper(TreeNode *root){
if(root->left)
{
inorderHelper(root->left);
}
result.push_back(root->val);
if(root->right)
{
inorderHelper(root->right);
}
}
private:
vector<int> result;
};