{"action":"opened","issue":{"url":"https://api.github.com/repos/zeqing-guo/algorithms-study/issues/52","repository_url":"https://api.github.com/repos/zeqing-guo/algorithms-study","labels_url":"https://api.github.com/repos/zeqing-guo/algorithms-study/issues/52/labels{/name}","comments_url":"https://api.github.com/repos/zeqing-guo/algorithms-study/issues/52/comments","events_url":"https://api.github.com/repos/zeqing-guo/algorithms-study/issues/52/events","html_url":"https://github.com/zeqing-guo/algorithms-study/issues/52","id":139861228,"number":52,"title":"Leetcode-101: Symmetric Tree","user":{"login":"zeqing-guo","id":4294005,"avatar_url":"https://avatars.githubusercontent.com/u/4294005?v=3","gravatar_id":"","url":"https://api.github.com/users/zeqing-guo","html_url":"https://github.com/zeqing-guo","followers_url":"https://api.github.com/users/zeqing-guo/followers","following_url":"https://api.github.com/users/zeqing-guo/following{/other_user}","gists_url":"https://api.github.com/users/zeqing-guo/gists{/gist_id}","starred_url":"https://api.github.com/users/zeqing-guo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zeqing-guo/subscriptions","organizations_url":"https://api.github.com/users/zeqing-guo/orgs","repos_url":"https://api.github.com/users/zeqing-guo/repos","events_url":"https://api.github.com/users/zeqing-guo/events{/privacy}","received_events_url":"https://api.github.com/users/zeqing-guo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/zeqing-guo/algorithms-study/labels/Depth-first%20Search","name":"Depth-first Search","color":"006b75"},{"url":"https://api.github.com/repos/zeqing-guo/algorithms-study/labels/Leetcode","name":"Leetcode","color":"f7c6c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-10T11:30:56Z","updated_at":"2016-03-10T11:30:56Z","closed_at":null,"body":"\n## Description\n\nGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).\n\nFor example, this binary tree is symmetric:\n\n\t    1\n\t   / \\\n\t  2   2\n\t / \\ / \\\n\t3  4 4  3\nBut the following is not:\n\t    1\n\t   / \\\n\t  2   2\n\t   \\   \\\n\t   3    3\n**Note:**\nBonus points if you could solve it both recursively and iteratively.\n\n## My Solution\n\n代码的 run time 是1 ms (22.55%)。时间复杂度是![O(n)](http://latex.codecogs.com/gif.latex?%5Cnormal%20O%28n%29)，空间复杂度是![O(n)](http://latex.codecogs.com/gif.latex?%5Cnormal%20O%28n%29)。\n\n\n```java\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n    private boolean isMirrorTree(TreeNode p, TreeNode q) {\n        if (p == null && q == null) {\n            return true;\n        } else if (p != null && q != null) {\n            return (p.val == q.val) && isMirrorTree(p.left, q.right) && isMirrorTree(p.right, q.left);\n        } else {\n            return false;\n        }\n    }\n    public boolean isSymmetric(TreeNode root) {\n        if (root == null) {\n            return true;\n        }\n        return isMirrorTree(root.left, root.right);\n    }\n}\n```\n\n## Analysis\n\nLeetcode 100是判断两棵树是否一致，本题101是判断两棵树是否互为镜像。\n"}}