404. Sum of Left Leaves
来源:互联网 发布:二端口ucd=0.1 编辑:程序博客网 时间:2024/04/30 17:21
Find the sum of all left leaves in a given binary tree.
Example:
3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.
代码:
class Solution{public:int sumOfLeftLeaves(TreeNode* root){return dfs(root, false);}private:int dfs(TreeNode* root, bool isleft){if(!root) return 0;if(!root->left && !root->right){return isleft ? root->val : 0;}return dfs(root->left, true) + dfs(root->right, false);}};
0 0
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves*
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- android 7.0对开发者会有哪些影响
- 在Excel中插入图片
- nrf51822 secure DFU by OTA: How to Set Password in the DFU zip File
- [leetcode]449. Serialize and Deserialize BST
- java Random()使用
- 404. Sum of Left Leaves
- 发布/订阅(Pub/Sub)
- ESP8266下cygdrive命令编译详解
- SQL Server删除重复行的6个方法
- 十六进制颜色值和ARGB颜色值的转换
- Spark Task执行原理
- Android 高仿微信朋友圈动态, 支持双击手势放大并滑动查看图片。
- Notification
- 平衡车之角度环分析及调试