public int getAns(TreeNode root) {
// write your code here
HashMap map = new HashMap();
map.put("max",1);
if(root == null) {
return 0;
}
findMax(root,map);
return (int)map.get("max");
}
public void findMax(TreeNode root,HashMap map){
//代表已到叶子节点
if(root.left == null&& root.right == null) {
/*int target = (int)map.get("max");
target++;
map.put("max",target);*/
return;
}
if(root.left != null){
map.put("max",(int)map.get("max")+1);
findMax(root.left,map);
}
if(root.right != null){
map.put("max",(int)map.get("max")+1);
findMax(root.right,map);
}
}