class Solution {
public:
bool hasPathSum(TreeNode* root, int targetSum) {
if(root)
{
int x=targetSum-root->val;
if(!root->left&&!root->right)
{
return x==0;
}
return hasPathSum(root->left,x)||hasPathSum(root->right,x);
}
else
{
return false;
}
}
};
前几天的链表,这两天的二叉树。
每次都会有一堆问题,花费大量的时间。
可是这几天也没什么时间鲨二叉树。
记账上了!
唉,加油。