leetcode 404. Sum of Left Leaves
int sumOfLeftLeaves(TreeNode* root) { if (root == NULL) return 0; int sum = 0; if (root->left && root->left->left == NULL && root->left->right == NULL) sum += root->left->val; int l = sumOfLeftLeaves(root->left); int r = sumOfLeftLeaves(root->right); return sum + l + r; }
【本文章出自博客园willaty,转载请注明作者出处,误差欢迎指出~】