Skip to content

Bug Report for same-binary-tree #4715

@adamhmielke

Description

@adamhmielke

Bug Report for https://neetcode.io/problems/same-binary-tree

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

The following code passes and is accepted:

def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
        if p == None and q == None:
            return True
        if (p == None and q !=None) or p!=None and q == None:
            return False
        if p.val != q.val:
            return False
        if (p.right == None and q.right != None) or (p.right != None and q.right == None):
            return False
        if (p.left == None and q.left != None) or (p.left != None and q.left == None):
            return False
        if p.right and q.right:
            return self.isSameTree(p.right, q.right)
        if p.left and q.left:
            return self.isSameTree(p.left, q.left)
        return True

This should fail and fails the test case

p=[1,2,4]
q=[1,3,4]

Please add this test case to the backend test cases to correct this.

Thank you so much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy