国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

LEETCODE--Sum of Left Leaves

2019-11-14 10:00:03
字體:
來源:轉載
供稿:網友

Find the sum of all left leaves in a given binary tree. Example: 3 / / 9 20 / / 15 7

There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.

/** * 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: int sumOfLeftLeaves(TreeNode* root) { if(!root) return 0; else if(root->left){ TreeNode* lc = root->left; if(!lc->left && !lc->right){ return lc->val + sumOfLeftLeaves(root->right); }else{ return sumOfLeftLeaves(root->left) + sumOfLeftLeaves(root->right); } } else return sumOfLeftLeaves(root->left) + sumOfLeftLeaves(root->right); }};
上一篇:異常處理

下一篇:java中的變量

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 芜湖市| 凤庆县| 宁武县| 拜泉县| 绩溪县| 永福县| 怀柔区| 绩溪县| 凉城县| 宁城县| 莎车县| 华亭县| 济阳县| 扎兰屯市| 台中县| 大厂| 西充县| 高邮市| 镇巴县| 儋州市| 芮城县| 广水市| 佛学| 蓬莱市| 玉林市| 永川市| 曲水县| 同德县| 桐梓县| 邵东县| 石首市| 和林格尔县| 砚山县| 靖宇县| 会理县| 虎林市| 塘沽区| 邯郸县| 同心县| 澄江县| 榕江县|