Why is this change necessary? What problem does it solve?
Closes #ISSUE_NUMBER
How does this PR solve the problem? What technical approach is taken?
How did you verify that this works? Were automated tests written?
| # Definition for a binary tree node. | |
| # class TreeNode: | |
| # def __init__(self, val=0, left=None, right=None): | |
| # self.val = val | |
| # self.left = left | |
| # self.right = right | |
| class Solution: | |
| def _left_first_traverse(self, node, depth): | |
| if node is None: | |
| return |
| class Solution: | |
| def coinChange(self, coins: List[int], amount: int) -> int: | |
| min_coins = [float("inf")] * (amount + 1) | |
| min_coins[0] = 0 | |
| for i in range(1, amount + 1): | |
| for coin_val in coins: | |
| if i - coin_val < 0: | |
| continue | |
| min_coins[i] = min( |
| class Solution: | |
| def depth_first_search(self, nums: List[int], curr_state: List[int], curr_idx: int): | |
| if curr_idx == len(nums): | |
| self.final_result.append(curr_state.copy()) | |
| return | |
| num = nums[curr_idx] | |
| curr_state.append(num) | |
| self.depth_first_search(nums, curr_state, curr_idx + 1) | |
| curr_state.pop() |
| from collections import deque | |
| # Definition for a binary tree node. | |
| # class TreeNode: | |
| # def __init__(self, val=0, left=None, right=None): | |
| # self.val = val | |
| # self.left = left | |
| # self.right = right | |
| class Solution: | |
| def append_or_overwrite(self, node: TreeNode, depth: int, seen: List[int]): | |
| if len(seen) == depth: |
| # Definition for a binary tree node. | |
| # class TreeNode: | |
| # def __init__(self, val=0, left=None, right=None): | |
| # self.val = val | |
| # self.left = left | |
| # self.right = right | |
| class Solution: | |
| def traverse_tree(self, node: Optional[TreeNode], depth: int, levels: list[list[int]]): | |
| if node is None: | |
| return |
| # Definition for a binary tree node. | |
| # class TreeNode: | |
| # def __init__(self, x): | |
| # self.val = x | |
| # self.left = None | |
| # self.right = None | |
| """ | |
| We need to binary search until we find our node p and our node q | |
| - generate a set of nodes we've seen while looking for p |
| # Definition for a binary tree node. | |
| # class TreeNode: | |
| # def __init__(self, val=0, left=None, right=None): | |
| # self.val = val | |
| # self.left = left | |
| # self.right = right | |
| class Solution: | |
| def identical_tree(self, root: Optional[TreeNode], subRoot: Optional[TreeNode]): | |
| if root is None or subRoot is None: |
| # Definition for a binary tree node. | |
| # class TreeNode: | |
| # def __init__(self, val=0, left=None, right=None): | |
| # self.val = val | |
| # self.left = left | |
| # self.right = right | |
| class Solution: | |
| def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool: | |
| if p is None or q is None: | |
| return p == q |
| # Definition for a binary tree node. | |
| # class TreeNode: | |
| # def __init__(self, val=0, left=None, right=None): | |
| # self.val = val | |
| # self.left = left | |
| # self.right = right | |
| """ | |
| We need to calculate the depth of the left and right | |
| subtree all the way down. If at any point that | |
| depth differs by > 1, we need a way to easily return |