题解 | #相同的二叉树# | Golang

相同的二叉树

https://www.nowcoder.com/practice/5a3b2cf4211249c89d6ced7987aeb775

package main
import . "nc_tools"
/*
 * type TreeNode struct {
 *   Val int
 *   Left *TreeNode
 *   Right *TreeNode
 * }
 */

/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 
 * @param root1 TreeNode类 
 * @param root2 TreeNode类 
 * @return bool布尔型
*/
func isSameTree( root1 *TreeNode ,  root2 *TreeNode ) bool {
    if root1 == nil && root2 == nil {
        return true
    }
    if root1 == nil || root2 == nil {
        return false
    }
    return root1.Val == root2.Val &&
           isSameTree(root1.Left, root2.Left) &&
           isSameTree(root1.Right, root2.Right)
}

全部评论

相关推荐

兄弟们你们进大厂靠的是什么项目啊
DOTPHTP:课设改。其实项目什么的如果不是实习里面的生产项目的话,建议✍️那种自己想要做的。突出个人自驱力,而不是为了找工作不得不随波逐流这种
点赞 评论 收藏
分享
点赞 评论 收藏
分享
frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务