代码实现:
public class FindTarget {
public boolean findTarget(TreeNode root, int k) {
if (root == null) return false;
Map hashMap = new HashMap<>();
return findTarget(root, k, hashMap);
}
public boolean findTarget(TreeNode root, int k, Map hashMap) {
if (root == null) return false;
if (hashMap.containsKey(root.val)){
return true;
}else {
hashMap.put(k - root.val,true);
}
return findTarget(root.left, k, hashMap) || findTarget(root.right, k, hashMap);
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)