max depth of binary tree
public class TreeNode{
TreeNode leftPointer,rightPointer;
int data;
public TreeNode(){
leftPointer= null;
rightPointer= null;
data = 0;
}
public TreeNode(int n ){
leftPointer=null;
rightPointer=null;
data=n;
}
public TreeNode getLeftPointer() {
return leftPointer;
}
public void setLeftPointer(TreeNode leftPointer) {
this.leftPointer = leftPointer;
}
public TreeNode getRightPointer() {
return rightPointer;
}
public void setRightPointer(TreeNode rightPointer) {
this.rightPointer = rightPointer;
}
public int getData() {
return data;
}
public void setData(int data) {
this.data = data;
}
public int maxDepth(TreeNode root){
if(root==null){return 0;}
return 1+Math.max(maxDepth(root.leftPointer),maxDepth(root.rightPointer));
}