标签:
题目描述:public bool HasPathSum(TreeNode root, int sum) { Find(root, 0, sum); return found; } private bool found = false; private void Find(TreeNode node, int sum, int target){ if(found || node == null){ return; } if(node.left == null && node.right == null){ if(sum + node.val == target){ found = true; } } Find(node.left, sum + node.val, target); Find(node.right, sum + node.val, target); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/lan_liang/article/details/49108383