Recursive Ruby solution


  • 0
    M

    Any suggestions to shorten the line length? It looks a bit messy and unclear in my opinion.

    def is_same_tree(p, q)
        if !p.nil? && !q.nil?
            return p.val == q.val ? is_same_tree(p.left, q.left) && is_same_tree(p.right, q.right) : false
        else
            return p.nil? && q.nil?
        end
    end
    

Log in to reply
 

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