Skip to content

Commit 54713c9

Browse files
committed
Feb 21
1 parent ef2d72b commit 54713c9

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import Optional
2+
3+
4+
# Definition for a binary tree node.
5+
class TreeNode:
6+
def __init__(self, val=0, left=None, right=None):
7+
self.val = val
8+
self.left = left
9+
self.right = right
10+
11+
12+
class FindElements:
13+
def __init__(self, root: Optional[TreeNode]):
14+
self.node_vals = set()
15+
16+
def dfs(node: Optional[TreeNode], val: int) -> None:
17+
if node is None:
18+
return
19+
node.val = val
20+
self.node_vals.add(val)
21+
dfs(node.left, 2*val + 1)
22+
dfs(node.right, 2*val + 2)
23+
dfs(root, 0)
24+
25+
def find(self, target: int) -> bool:
26+
return target in self.node_vals
27+
28+
29+
def main():
30+
root = TreeNode(-1)
31+
root.right = TreeNode(-1)
32+
obj = FindElements(root)
33+
assert obj.find(1) is False
34+
assert obj.find(2) is True
35+
36+
37+
if __name__ == '__main__':
38+
main()

2025-02-February-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
| February 18 | [2375. Construct Smallest Number From DI String](https://leetcode.com/problems/construct-smallest-number-from-di-string/) | Medium | Unsolved |
2525
| February 19 | [1415. The k-th Lexicographical String of All Happy Strings of Length n](https://leetcode.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n/) | Medium | Unsolved |
2626
| February 20 | [1980. Find Unique Binary String](https://leetcode.com/problems/find-unique-binary-string/) | Medium | Solved |
27-
| February 21 | []() | | |
27+
| February 21 | [1261. Find Elements in a Contaminated Binary Tree](https://leetcode.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | Solved |
2828
| February 22 | []() | | |
2929
| February 23 | []() | | |
3030
| February 24 | []() | | |
@@ -38,5 +38,5 @@
3838
| Level | Problems | Solved | Unsolved |
3939
| --- | --- | --- | --- |
4040
| Easy | 6 | 6 | 0 |
41-
| Medium | 13 | 10 | 3 |
41+
| Medium | 14 | 11 | 3 |
4242
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)