Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are given a TreeNode, and you have to write an algorithm which will return the no. of nodes in the tree.

Go down

You are given a TreeNode, and you have to write an algorithm which will return the no. of nodes in the tree. Empty You are given a TreeNode, and you have to write an algorithm which will return the no. of nodes in the tree.

Post  skyboard Sat Sep 03, 2011 4:41 pm

public static getNumber(TreeNode root){
if(root==null)
return 0;
return (getNumber(root.getleft())+getNumber(root.getright())+1);
}

skyboard

Posts : 31
Join date : 2011-09-03

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum