测试数据 [8, 12, 2, 3, 9, 6, 4, null, null, 7, null,null, 81, 33, null]
/**
* 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:
void inorder(TreeNode* root)
{
if(!root) return;
cout<<root->val<<"->";
if(root->left)
inorder(root->left);
if(root->right)
inorder(root->right);
}
void midorder(TreeNode* root)
{
if(!root) return;
if(root->left)
midorder(root->left);
cout<<root->val<<"->";
if(root->right)
midorder(root->right);
}
void backorder(TreeNode* root)
{
if(!root) return;
if(root->left)
backorder(root->left);
if(root->right)
backorder(root->right);
cout<<root->val<<"->";
}
int pathSum(TreeNode* root) {
inorder(root);
puts("----------------");
midorder(root);
puts("----------------");
backorder(root);
puts("----------------");
return 0;
}
};