-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Bug Report for https://neetcode.io/problems/lowest-common-ancestor-in-binary-search-tree
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
def dfs(node):
if not node:
return None
# Compare by node identity (preferred for this problem)
if node is p or node is q:
return node
left = dfs(node.left)
right = dfs(node.right)
if left and right:
return node
return left or right
return dfs(root)
this solution is good i think. I tested on Leetcode as well and it works fine.
But here i am getting error:
Traceback (most recent call last):
File "/box/main.py", line 90, in
raise TypeError(f"Your output was {outputNode}, but the expected return type is TreeNode")
TypeError: Your output was None, but the expected return type is TreeNode
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels