94. Binary Tree Inorder Traversal
Medium
183278FavoriteShare
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]
class Solution
{
public:
vector<int> inorderTraversal(TreeNode* root)
{
vector<int> res;
Inorder(root, res);
return res;
}
void Inorder(TreeNode* root, vector<int>&res)
{
if (root == NULL) { return; }
Inorder(root->left,res);
res.push_back(root->val);
Inorder(root->right, res);
}
};