Bug Report for lowest-common-ancestor-in-binary-search-tree
Opened this issue · 0 comments
subhajit033 commented
Bug Report for https://neetcode.io/problems/lowest-common-ancestor-in-binary-search-tree
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
/**
- Definition for a binary tree node.
- struct TreeNode {
-
int val; -
TreeNode *left; -
TreeNode *right; -
TreeNode(int x) : val(x), left(NULL), right(NULL) {} - };
*/
class Solution { public: TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { if(!root || root == p || root == q){ return root; } TreeNode* left = lowestCommonAncestor(root->left, p, q); TreeNode* right = lowestCommonAncestor(root->right, p, q); if(!left){ return right; }else if(!right){ return left; } return root; } };
the above one is my code, which was accepted by leetcode
but when I am trying to submit the code same code in neetcode , I am getting the below error
