Skip to content

Commit 4d61653

Browse files
committed
feat: add typescript solution to lc problem: No.0653.Two Sum IV - Input is a BST
1 parent 91c931a commit 4d61653

File tree

1 file changed

+31
-0
lines changed
  • solution/0600-0699/0653.Two Sum IV - Input is a BST

1 file changed

+31
-0
lines changed

solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,37 @@ class Solution {
119119
}
120120
```
121121

122+
### **TypeScript**
123+
124+
```ts
125+
/**
126+
* Definition for a binary tree node.
127+
* class TreeNode {
128+
* val: number
129+
* left: TreeNode | null
130+
* right: TreeNode | null
131+
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
132+
* this.val = (val===undefined ? 0 : val)
133+
* this.left = (left===undefined ? null : left)
134+
* this.right = (right===undefined ? null : right)
135+
* }
136+
* }
137+
*/
138+
139+
function findTarget(root: TreeNode | null, k: number): boolean {
140+
let set: Set<number> = new Set();
141+
return find(root, k, set);
142+
};
143+
144+
145+
function find(root: TreeNode | null, k: number, set: Set<number>): boolean {
146+
if (!root) return false;
147+
if (set.has(k - root.val)) return true;
148+
set.add(root.val);
149+
return find(root.left, k, set) || find(root.right, k, set);
150+
}
151+
```
152+
122153
### **C++**
123154

124155
```cpp

0 commit comments

Comments
 (0)