---
# System prepended metadata

title: LeetCode 101. Symmetric Tree
tags: [Leetcode]

---

---
title: 'LeetCode 101. Symmetric Tree'
disqus: hackmd
---

# LeetCode 101. Symmetric Tree



## Description

Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).

## Example

Input: root = [1,2,2,3,4,4,3]
Output: true

Input: root = [1,2,2,null,3,null,3]
Output: false

## Constraints

The number of nodes in the tree is in the range [1, 1000].
-100 <= Node.val <= 100

## Answer

此題可用same tree的概念，只是same tree是檢查同一側，而此提只要換成檢查不同側即可。

```Cin=
// 2022_05_02
bool isSametree(struct TreeNode* L, struct TreeNode* R){
    if(L == NULL && R == NULL){return true;}
    else if(L == NULL || R == NULL){return false;}
    else{
        return (L->val == R->val) && isSametree(L->left,R->right) && isSametree(L->right,R->left);
    }
}
bool isSymmetric(struct TreeNode* root){
    if(root == NULL){return true;}
    return isSametree(root->left,root->right);
}
```



## Link
https://leetcode.com/problems/symmetric-tree/
###### tags: `Leetcode` 
