You are given a TreeNode, and you have to write an algorithm which will return the no. of nodes in the tree.
Page 1 of 1
You are given a TreeNode, and you have to write an algorithm which will return the no. of nodes in the tree.
public static getNumber(TreeNode root){
if(root==null)
return 0;
return (getNumber(root.getleft())+getNumber(root.getright())+1);
}
if(root==null)
return 0;
return (getNumber(root.getleft())+getNumber(root.getright())+1);
}
skyboard- Posts : 31
Join date : 2011-09-03
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum