package com.fishercoder.solutions;

import com.fishercoder.common.classes.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class _653 {

    public static class Solution1 {
        public boolean findTarget(TreeNode root, int k) {
            if (root == null) {
                return false;
            }
            List<Integer> list = new ArrayList<>();
            dfs(root, list);
            for (int i = 0; i < list.size() - 1; i++) {
                for (int j = i + 1; j < list.size(); j++) {
                    if (list.get(i) + list.get(j) == k) {
                        return true;
                    }
                }
            }
            return false;
        }

        private void dfs(TreeNode root, List<Integer> list) {
            list.add(root.val);
            if (root.left != null) {
                dfs(root.left, list);
            }
            if (root.right != null) {
                dfs(root.right, list);
            }
        }
    }
}

@@ -123,19 +123,67 @@
 va.util.
-Lis
+HashSet;%0Aimport java.util.List;%0Aimport java.util.Se
 t;%0A%0Apubl
@@ -1041,11 +1041,518 @@
  %7D%0A    %7D
+%0A%0A    public static class Solution2 %7B%0A        public boolean findTarget(TreeNode root, int k) %7B%0A            return dfs(root, new HashSet(), k);%0A        %7D%0A%0A        private boolean dfs(TreeNode root, Set%3CInteger%3E set, int k) %7B%0A            if (root == null) %7B%0A                return false;%0A            %7D%0A%0A            if (set.contains(k - root.val)) %7B%0A                return true;%0A            %7D%0A            set.add(root.val);%0A            return dfs(root.left, set, k) %7C%7C dfs(root.right, set, k);%0A        %7D%0A    %7D
 %0A%7D%0A

add a solution for 653