C语言
#include "stdbool.h" #define NULL ((void *)0) //Definition for a binary tree node. struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; }; bool check(struct TreeNode* p, struct TreeNode* q) { if (!p && !q) return true; if (!p || !q) return false; return p->val == q->val && check(p->left, q->right) && check(p->right, q->left); } bool isSymmetric(struct TreeNode* root) { return check(root, root); }