{"id":127,"date":"2017-08-26T20:27:04","date_gmt":"2017-08-26T12:27:04","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=127"},"modified":"2018-11-27T16:28:14","modified_gmt":"2018-11-27T08:28:14","slug":"100-same-tree","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=127","title":{"rendered":"100. Same Tree"},"content":{"rendered":"<p>Given two binary trees, write a function to check if they are the same or not.<\/p>\n<p>Two binary trees are considered the same if they are structurally identical and the nodes have the same value.<\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<pre><strong>Input:<\/strong>     1         1\r\n          \/ \\       \/ \\\r\n         2   3     2   3\r\n\r\n        [1,2,3],   [1,2,3]\r\n\r\n<strong>Output:<\/strong> true\r\n<\/pre>\n<p><strong>Example 2:<\/strong><\/p>\n<pre><strong>Input:<\/strong>     1         1\r\n          \/           \\\r\n         2             2\r\n\r\n        [1,2],     [1,null,2]\r\n\r\n<strong>Output:<\/strong> false\r\n<\/pre>\n<p><strong>Example 3:<\/strong><\/p>\n<pre><strong>Input:<\/strong>     1         1\r\n          \/ \\       \/ \\\r\n         2   1     1   2\r\n\r\n        [1,2,1],   [1,1,2]\r\n\r\n<strong>Output:<\/strong> false<\/pre>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution(object):\r\n    def isSameTree(self, p, q):\r\n        &quot;&quot;&quot;\r\n        :type p: TreeNode\r\n        :type q: TreeNode\r\n        :rtype: bool\r\n        &quot;&quot;&quot;\r\n        if p is None and q is None:\r\n            return True\r\n        elif p is None or q is None:\r\n            return False\r\n        if p.val != q.val:\r\n            return False\r\n        return self.isSameTree(p.right, q.right) and self.isSameTree(p.left, q.left)\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Given two binary trees, write a function to check if th<a href=\"https:\/\/www.ccagml.com\/?p=127\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">100. Same Tree<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/127"}],"collection":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=127"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions"}],"predecessor-version":[{"id":128,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions\/128"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}