标签:路径 ret main als node int rem || 子节点
路径总和
class Solution { public: bool hasPathSum(TreeNode* root, int sum) { return dfs(root, sum); } bool dfs(TreeNode *t, int remain) { if(t == NULL) return false; else { // 叶子节点 if(t->left == NULL && t->right == NULL) { return t->val == remain; } else { return dfs(t->left, remain - t->val) || dfs(t->right, remain - t->val); } } } };
标签:路径 ret main als node int rem || 子节点
原文地址:https://www.cnblogs.com/yangwenhuan/p/12454126.html