public static int maxDepth(TreeNode root) {
		if(root==null) return 0;
		Stack<TreeNode> stack = new Stack<TreeNode>();
		HashMap<TreeNode, Integer> depthTable = new HashMap<TreeNode, Integer>();
		stack.add(root);
		depthTable.put(root,1);
		int maxDepth = 1;
		while(!stack.isEmpty()) {
			TreeNode node = stack.pop();
			Integer depth = depthTable.get(node);			
			if(!(node.right==null || depthTable.containsKey(node.right))) {
				stack.add(node.right);
				depthTable.put(node.right, depth+1);
			}
			if(!(node.left==null || depthTable.containsKey(node.left))) {
				stack.add(node.left);
				depthTable.put(node.left, depth+1);
			}
			if(node.left==null && node.right==null) {
				if(depth>maxDepth) {
					maxDepth = depth;
				}
			}
		}
		return maxDepth;
	}