upload to gh
This commit is contained in:
parent
d9d8d06b8a
commit
f2407a9587
33 changed files with 941 additions and 83 deletions
16
src/day1/BTBFS.ts
Normal file
16
src/day1/BTBFS.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
export default function bfs(head: BinaryNode<number>, needle: number): boolean {
|
||||
const q: (BinaryNode<number>|null)[] = [head];
|
||||
while(q.length){
|
||||
const curr = q.shift() as BinaryNode<number> | undefined | null;
|
||||
|
||||
if(!curr){
|
||||
continue;
|
||||
}
|
||||
if (curr.value === needle){
|
||||
return true;
|
||||
}
|
||||
q.push(curr.left);
|
||||
q.push(curr.right);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue