/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
//不需考虑重复元素
Set<Integer> set = new HashSet<Integer>();
public boolean findTarget(TreeNode root, int k) {
if (root == null)
return false;
if (set.contains(k - root.val))
return true;
set.add(root.val);
return findTarget(root.left, k) || findTarget(root.right, k);
}
}
两数之和IV
最新推荐文章于 2024-08-17 15:37:21 发布