Leetcode 94. Binary Tree Inorder Traversal
中序遍历,常规操作
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: vector<int> inorderTraversal(TreeNode* root) { vector<int> v; inorder(v,root); return v; } void inorder(vector<int>& v, TreeNode* root) { if(!root) return; inorder(v, root->left); v.push_back(root->val); inorder(v, root->right); } };