原题:
Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3}
,
[1,3,2]
.
二叉树的中序遍历,废话不说,和先序遍历几乎一样
代码(24ms):
class Solution {
public:
vector<int> inorderTraversal(TreeNode *root) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
vector<int> result;
inOrder(root,result);
return result;
}
void inOrder(TreeNode*root , vector<int>&result){
if(!root)return;
inOrder(root->left , result);
result.push_back(root->val);
inOrder(root->right , result);
}
};