题目:
题解:
func isSymmetric(root *TreeNode) bool { u, v := root, root q := []*TreeNode{} q = append(q, u) q = append(q, v) for len(q) > 0 { u, v = q[0], q[1] q = q[2:] if u == nil && v == nil { continue } if u == nil || v == nil { return false } if u.Val != v.Val { return false } q = append(q, u.Left) q = append(q, v.Right) q = append(q, u.Right) q = append(q, v.Left) } return true }
还没有评论,来说两句吧...