Sum Root to Leaf Numbers Posted on 2018-09-24 Descrpitionhttps://leetcode.com/problems/sum-root-to-leaf-numbers/description/ Solution12345678910111213141516171819class Solution {public: int sumNumbers(TreeNode* root) { if (root == NULL) return 0; int ret = 0; int currentSum = 0; this->sumLeafNode(root, ret, currentSum); return ret; } void sumLeafNode(TreeNode* root, int& ret, int& currentSum) { if (root == NULL) return; currentSum = currentSum * 10 + root->val; if (root->left == NULL && root->right == NULL) ret += currentSum; this->sumLeafNode(root->left, ret, currentSum); this->sumLeafNode(root->right, ret, currentSum); currentSum = currentSum / 10; }};