A golang soultion


  • 0
    N
    func isSameTree(p *TreeNode, q *TreeNode) bool {
        switch {
    	case p == nil && q == nil:
    		return true
    	case p != nil && q == nil:
    		return false
    	case p == nil && q != nil:
    		return false
    	default:
    		if p.Val != q.Val {
    			return false
    		} else {
    			return isSameTree(p.Left, q.Left) && isSameTree(p.Right, q.Right)
    		}
    	}
    }

Log in to reply
 

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