-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path101.php
More file actions
37 lines (34 loc) · 936 Bytes
/
101.php
File metadata and controls
37 lines (34 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/**
* Definition for a binary tree node.
* class TreeNode {
* public $val = null;
* public $left = null;
* public $right = null;
* function __construct($value) { $this->val = $value; }
* }
*/
class Solution {
/**
* @param TreeNode $root
* @return Boolean
*/
function isSymmetric($root)
{
$this->isSymmetricRec($root, $root);
}
/**
* @param TreeNode $left_root
* @param TreeNode $right_root
* @return Boolean
*/
function isSymmetricRec($left_root, $right_root)
{
if ($left_root == null && $right_root == null) return true;
if ($left_root == null || $right_root == null) return false;
if ($left_root->val == $right_root->val) {
return $this->isSymmetricRec($left_root->left, $right_root->right) && $this->isSymmetricRec($left_root->right, $right_root->left);
}
return false;
}
}