18. Sum of leaf nodes in BST
My Approach
Time and Auxiliary Space Complexity
Code (C++)
class Solution {
public:
int sumOfLeafNodes(Node *root) {
if (!root)
return 0;
if (!root->left && !root->right)
return root->data;
return sumOfLeafNodes(root->left) + sumOfLeafNodes(root->right);
}
};Contribution and Support
Last updated