Esempio n. 1
0
bool HasPathSum(node* root , int sum)
{
	if(root == NULL)
		return (sum == 0);
	else{
		int newSum = sum - root->val;
		return (HasPathSum(root->left, newSum) || HasPathSum(root->right, newSum));

	}

}
Esempio n. 2
0
 bool HasPathSum(TreeNode *root, const int sum,int curSum)
 {
     if(root == NULL) 
     	return false;
     if(root->left == NULL && root->right == NULL)
     	if(curSum + root->val == sum)
     		return true;
     bool left = HasPathSum(root->left,sum,curSum + root->val);
     if(left)
     	 return true;
    	bool right = HasPathSum(root->right,sum, curSum + root->val);
    	if(right)
    		return true;
    	return false;
 }
Esempio n. 3
0
int main(){

	node* root = NULL;
	Insert(root, 4);
	Insert(root, 2);
	Insert(root, 6);
	Insert(root, 1);
	Insert(root, 3);

	PrintPaths(root);
	std::cout << std::endl;
	int x = Size(root);
		std::cout << x <<" ---" << std::endl;
	int y = MaxDepth(root);	
	std::cout << "depth= " << y << std::endl;

	int min = MinValue(root);
	std::cout << "min= " << min << std::endl;

	if(HasPathSum(root,10))
		std::cout <<"yessss"<< std::endl;
return 0;
}
Esempio n. 4
0
 bool hasPathSum(TreeNode *root, int sum) {
     HasPathSum(root,sum,0);
 }