(left, right *TreeNode)
| 20 | } |
| 21 | |
| 22 | func isSym(left, right *TreeNode) bool { |
| 23 | if left == nil && right == nil { |
| 24 | return true |
| 25 | } |
| 26 | |
| 27 | // if left XOR right is nil (check above makes XOR) |
| 28 | if left == nil || right == nil { |
| 29 | return false |
| 30 | } |
| 31 | |
| 32 | return (left.Val == right.Val) && |
| 33 | isSym(right.Left, left.Right) && |
| 34 | isSym(left.Left, right.Right) |
| 35 | } |
| 36 | |
| 37 | // Based on in-order traversal being a palindrome. |
| 38 | // Wrong approach but good lesson on array appending in recursive function. |