使用dfs遍历树,将遍历结果加入集合中,如果集合中存在与当前节点值之和为目标值的元素,返回true /** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * }; */ class Solution { private: bool dfs(TreeNode* root, unordered_set<int>& st, int k) { i...