Skip to content

Instantly share code, notes, and snippets.

@beyondkmp
Created July 22, 2015 06:29
Show Gist options
  • Select an option

  • Save beyondkmp/119d5a2c745896684a3f to your computer and use it in GitHub Desktop.

Select an option

Save beyondkmp/119d5a2c745896684a3f to your computer and use it in GitHub Desktop.

Revisions

  1. beyondkmp created this gist Jul 22, 2015.
    25 changes: 25 additions & 0 deletions isSymmetric.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    /**
    * Definition for a binary tree node.
    * struct TreeNode {
    * int val;
    * struct TreeNode *left;
    * struct TreeNode *right;
    * };
    */

    bool isChildSymmetric(struct TreeNode* p, struct TreeNode* q) {

    if(!p && !q)
    return true;
    if(!p || !q)
    return false;
    return((p->val==q->val) && isChildSymmetric(p->left,q->right) && isChildSymmetric(p->right,q->left));
    }


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

    }