1. 程式人生 > >101 Symmetric Tree

101 Symmetric Tree

題意:

判斷一顆二叉樹是否對稱

程式碼:

bool comp(TreeNode* l, TreeNode* r) {
	if (l == NULL&&r == NULL)
		return true;
	if (l == NULL||r == NULL)
		return false;
	if (l->val != r->val)
		return false;
	return comp(l->left, r->right) && comp(l->right, r->left);

}

bool isSymmetric
(TreeNode* root) { if (!root) return true; return comp(root->left, root->right); }