101. 对称二叉树

题目链接:https://leetcode-cn.com/problems/symmetric-tree/

执行用时:12 ms, 在所有 Swift 提交中击败了80.58%的用户
内存消耗:13.3 MB, 在所有 Swift 提交中击败了98.35%的用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
func isSymmetric(_ root: TreeNode?) -> Bool {

func check(_ l: TreeNode?, _ r: TreeNode?) -> Bool {
if l == nil && r == nil {
return true
}

if l == nil || r == nil {
return false
}

if l?.val == r?.val && check(l?.left, r?.right) && check(l?.right, r?.left) {
return true
}
return false
}
return check(root, root)
}
}

101. 对称二叉树
https://pisces34.github.io/2021/10/01/leetcode/101/
发布于
2021年10月1日
许可协议