/** * 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, bool isLeft = false) { int res = 0; if (root == NULL) return res; if (root->left == NULL && root->right == NULL && isLeft) return root->val; res += sumOfLeftLeaves(root->left, true); res += sumOfLeftLeaves(root->right, false); return res; } };
404. Sum of Left Leaves
猜你喜欢
转载自www.cnblogs.com/JTechRoad/p/9092955.html
今日推荐
周排行