Skip to content

相同的树 #21

@JesseZhao1990

Description

@JesseZhao1990

image

/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} p
 * @param {TreeNode} q
 * @return {boolean}
 */
var isSameTree = function(p, q) {
    if(p===null || q===null){
        return p === q;
    }
    if(p.val == q.val){
        return isSameTree(p.left,q.left) && isSameTree(p.right,q.right);
    }else{
        return false;
    }
};

leetcode原题地址:https://leetcode-cn.com/problems/same-tree/description/

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions