Advertisement
vaibhav1906

Count complete tree Nodes

Jan 7th, 2022
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     void f(TreeNode* root, int &count){
  4.        
  5.         if(root==NULL)return;
  6.        
  7.         f(root->left,count);
  8.         count++;
  9.         f(root->right,count);
  10.        
  11.         return;
  12.        
  13.     }
  14.     int countNodes(TreeNode* root) {
  15.         int count = 0;
  16.         f(root,count);
  17.        
  18.         return count;
  19.     }
  20. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement