Given a binary tree, return the inorder traversal of its nodes’ values.
Example:
Input: [1,null,2,3]
1
2
/
3
Output: [1,3,2]
C++
vector<int> inorderTraversal(TreeNode* root) {
vector<int> res;
DFS(root,res);
return res;
}
void DFS(TreeNode* root,vector<int>& res)
{
if(root)
{
if(root->left)DFS(root->left,res);
res.push_back(root->val);
if(root->right)DFS(root->right,res);
}
else
return;
}