Same-Tree

Jan 26, 2018

第95天。

今天的题目比较水。

今天的题目是Same Tree:

Given two binary trees, write a function to check if they are the same or not.

Two binary trees are considered the same if they are structurally identical and the nodes have the same value.

太简单了,不做太多解释了:

bool isSameTree(TreeNode* p, TreeNode* q) {
    if (p == nullptr && q == nullptr) return true;
    else if (p && q) {
        return q->val == p->val && isSameTree(p->left,q->left) && isSameTree(p->right,q->right);
    } else return false;
}
LeetCodeLeetCode

Search-a-2D-Matrix-II

Nim-Game

comments powered by Disqus