Posted on 2014-01-18 02:44
Uriel 阅读(98)
评论(0) 编辑 收藏 引用 所属分类:
LeetCode
裸的中序遍历二叉树,想着用来练记事本直接写代码能力来着,结果CE一次,敲错一个字母...囧
1 /**
2 * Definition for binary tree
3 * struct TreeNode {
4 * int val;
5 * TreeNode *left;
6 * TreeNode *right;
7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8 * };
9 */
10 class Solution {
11 public:
12 vector<int> res;
13
14 void inorder(TreeNode *root) {
15 if(root->left != NULL) inorder(root->left);
16 res.push_back(root->val);
17 if(root->right != NULL) inorder(root->right);
18 }
19
20 vector<int> inorderTraversal(TreeNode *root) {
21 res.clear();
22 if(root == NULL) return res;
23 inorder(root);
24 return res;
25 }
26 };