Simple recursive ruby solution


  • 0
    N
    def is_same_tree(p, q)
        if !p and !q
            return true
        end
        
        if p and q and p.val == q.val
            return (is_same_tree(p.left, q.left) and is_same_tree(p.right, q.right))
        end
        return false
    end

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.