653. Two Sum IV
来源:互联网 发布:手机mac地址可以修改吗 编辑:程序博客网 时间:2024/05/19 19:13
Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.
Example 1:
Input: 5 / \ 3 6 / \ \2 4 7Target = 9Output: True
Example 2:
Input: 5 / \ 3 6 / \ \2 4 7Target = 28Output: False
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public boolean findTarget(TreeNode root, int k) { return find(root, new HashSet<>(), k); } public boolean find(TreeNode root, HashSet<Integer> mem, int k){ if (root == null) return false; if (mem.contains(k - root.val)) return true; mem.add(root.val); return find(root.left, mem, k) || find(root.right, mem, k); }}
阅读全文
0 0
- 653. Two Sum IV
- 653. Two Sum IV
- 653. Two Sum IV
- 653. Two Sum IV
- 653. Two Sum IV
- 653. Two Sum IV
- 653. Two Sum IV
- 653. Two Sum IV
- 653. Two Sum IV
- 653. Two Sum IV
- 653. Two Sum IV
- leetcode 653. Two Sum IV
- Leetcode 653. Two Sum IV
- 【LeetCode】653. Two Sum IV
- Leetcode 653. Two Sum IV
- 【LeetCode】653. Two Sum IV
- leetcode 653. Two Sum IV
- leetcode 653. Two Sum IV
- 最后一个月,这3个趋势是网页设计师的最爱
- 备忘ACID,隔离级别等
- 浅谈小程序内嵌网页及内嵌网页跳转分享实现
- 英特尔专家告诉你 信息时代如何掌控数据安全(附视频&PPT)
- 继承中的初始化顺序
- 653. Two Sum IV
- 史上最全!阿里智能人机交互的核心技术解析
- 索引的设计和使用
- ffmpeg安装
- JPA持久化注释和Hibernate
- java中的数据类型
- MySQLSTR_TO_DATE函数
- springboot学习总结系列(一):多环境下(开发环境,生产环境)使用yml 或 properties 配置文件
- nginx基本配置与参数说明