Simple cpp solution

class Solution { public: int getNumber(int sum, TreeNode* root){ if (root==NULL) return 0; int s = sum*10 + root>val; if (root>right == NULL && root>left == NULL){ return s; } return getNumber(s, root>left) + getNumber(s, root>right); } int sumNumbers(TreeNode* root) { if (!root) return 0; return getNumber(0, root); } };