int sum(struct TreeNode* root, int tmp_sum) { if (root == NULL) return 0; if (root->left == root->right) { return tmp_sum * 10 + root->val; } return sum(root->left, tmp_sum * 10 + root->val) + sum(root->right, tmp_sum * 10 + root->val); } int sumNumbers(struct TreeNode* root){ return sum(root, 0); }
int sum(struct TreeNode* root, int tmp_sum) { if (root == NULL) return 0; if (root->left == root->right) { return tmp_sum * 10 + root->val; } return sum(root->left, tmp_sum * 10 + root->val) + sum(root->right, tmp_sum * 10 + root->val); } int sumNumbers(struct TreeNode* root){ return sum(root, 0); }