[mypy] Fix type annotations in data_structures/binary_tree (#5518)

* fix: fix mypy errors

Update binary_search_tree `arr` argument to be typed as a list
within `find_kth_smallest` function

Update return type of `merge_two_binary_trees` as both inputs can
be None which means that a None type value can be returned from
this function

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Sherman Hui 2021-10-22 07:07:05 -07:00 committed by GitHub
parent d82cf5292f
commit 629848e372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 2 deletions

View File

@ -272,6 +272,7 @@
## Electronics
* [Carrier Concentration](https://github.com/TheAlgorithms/Python/blob/master/electronics/carrier_concentration.py)
* [Coulombs Law](https://github.com/TheAlgorithms/Python/blob/master/electronics/coulombs_law.py)
* [Electric Power](https://github.com/TheAlgorithms/Python/blob/master/electronics/electric_power.py)
* [Ohms Law](https://github.com/TheAlgorithms/Python/blob/master/electronics/ohms_law.py)

View File

@ -151,7 +151,7 @@ class BinarySearchTree:
def find_kth_smallest(self, k: int, node: Node) -> int:
"""Return the kth smallest element in a binary search tree"""
arr = []
arr: list = []
self.inorder(arr, node) # append all values to list using inorder traversal
return arr[k - 1]

View File

@ -7,6 +7,8 @@ will be used as the node of new tree.
"""
from __future__ import annotations
from typing import Optional
class Node:
"""
@ -19,7 +21,7 @@ class Node:
self.right: Node | None = None
def merge_two_binary_trees(tree1: Node | None, tree2: Node | None) -> Node:
def merge_two_binary_trees(tree1: Node | None, tree2: Node | None) -> Optional[Node]:
"""
Returns root node of the merged tree.