I don't understand why my solution is timing out (takes 120-130ms) - my understanding is since we are counting number of nodes, we should be visiting all the nodes. Can we do better than this? Am I missing anything?

class Solution {

public:

int countNodes(TreeNode* root) {

if (root == NULL) {

return 0;

}

return 1 + countNodes(root->left) + countNodes(root->right);

}

};