Skip to content

Commit 544ecf0

Browse files
authored
Create 653-two-sum-iv-input-is-a-bst.js
1 parent f6a8d89 commit 544ecf0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

653-two-sum-iv-input-is-a-bst.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val) {
4+
* this.val = val;
5+
* this.left = this.right = null;
6+
* }
7+
*/
8+
/**
9+
* @param {TreeNode} root
10+
* @param {number} k
11+
* @return {boolean}
12+
*/
13+
const findTarget = function(root, k) {
14+
const m = new Map()
15+
return traverse(root, k, m)
16+
};
17+
18+
function traverse(node, k, m) {
19+
if(node == null) return false
20+
if(m.has(k - node.val)) return true
21+
m.set(node.val, node)
22+
return traverse(node.left,k,m) || traverse(node.right,k,m)
23+
}

0 commit comments

Comments
 (0)