LeetCode_path-sum
来源:互联网 发布:java核心技术 编辑:程序博客网 时间:2024/06/09 13:41
原题链接:https://leetcode.com/problems/path-sum/
/** * Definition for a binary tree node. * 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) { if(!root) return false; bool flag = false; hasPathSum(root,sum,flag); return flag; } void hasPathSum(TreeNode* root,int sum,bool &flag) { if(!root->left && !root->right) { if(sum == root->val) { flag = true; return; } return; } sum -= root->val; if(root->left) hasPathSum(root->left,sum,flag); if(root->right) hasPathSum(root->right,sum,flag); }};
0 0
- LeetCode_Path Sum
- LeetCode_Path Sum
- Leetcode_Path Sum
- LeetCode_Path Sum
- LeetCode_path-sum
- LeetCode_Path Sum II
- *Leetcode_path-sum-ii
- LeetCode_Path Sum II
- Leetcode_Path Sum II
- LeetCode_Path Sum II
- Leetcode_path-sum (updated c++ and python version)
- Sum
- sum
- sum
- Sum
- Sum
- Sum
- sum
- Android核心基础-9.Android四大组件之BroadcastReceiver
- 2.1.2 RGB Cube (about vertex output parameters) RGB立方体(关于顶点输出参数)
- Altium_Designer如何快速寻找元件和封装
- 算法数据结构之贪心算法
- 导出pdf(表格形式)
- LeetCode_path-sum
- easyUI的高级查询
- C++11 nullptr
- mysql大数据高并发处理(转载)
- java实习--json格式串记录
- Delphi上位机
- 15-读乐嘉《本色》
- sql查询性能调试,用SET STATISTICS IO和SET STATISTICS TIME
- Nginx在Linux和windows下的安装使用