leetcode - Path Sum
2013-11-02 21:14
363 查看
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: bool hasPathSum(TreeNode *root, int sum) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. if (root == NULL) return false; if (root->left == NULL && root->right ==NULL && root->val == sum) return true; return hasPathSum(root->left,sum-root->val) || hasPathSum(root->right,sum-root->val); } };
相关文章推荐
- [LeetCode] Path Sum
- LeetCode112——Path Sum
- [Leetcode] Path Sum
- LeetCode--Path Sum
- leetcode 64. Minimum Path Sum
- leetcode笔记:Path Sum
- Leetcode 112 Path Sum
- leetcode [Path Sum]//待整理多种解法
- [leetcode] 64. Minimum Path Sum
- leetcode 64. Minimum Path Sum
- LeetCode 64. Minimum Path Sum
- Leetcode-112. Path Sum
- LeetCode 112. Path Sum
- LeetCode112——path sum
- [LeetCode]112. Path Sum
- [LeetCode]Path Sum
- 【LeetCode】64. Minimum Path Sum
- LeetCode - 64. Minimum Path Sum
- [LeetCode]64.Minimum Path Sum
- 和大神们学习每天一题(leetcode)-Path Sum