Skip to content

Commit d3b0cc9

Browse files
authored
feat: add php solution to lc problem: No.0100 (#932)
No.0100.Same Tree
1 parent ea0a775 commit d3b0cc9

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

solution/0100-0199/0100.Same Tree/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,43 @@ impl Solution {
566566
}
567567
```
568568

569+
### **PHP**
570+
571+
```php
572+
/**
573+
* Definition for a binary tree node.
574+
* class TreeNode {
575+
* public $val = null;
576+
* public $left = null;
577+
* public $right = null;
578+
* function __construct($val = 0, $left = null, $right = null) {
579+
* $this->val = $val;
580+
* $this->left = $left;
581+
* $this->right = $right;
582+
* }
583+
* }
584+
*/
585+
class Solution {
586+
/**
587+
* @param TreeNode $p
588+
* @param TreeNode $q
589+
* @return Boolean
590+
*/
591+
function isSameTree($p, $q) {
592+
if ($p == Null && $q == Null) {
593+
return true;
594+
}
595+
if ($p == Null || $q == Null) {
596+
return false;
597+
}
598+
if ($p->val != $q->val) {
599+
return false;
600+
}
601+
return $this->isSameTree($p->left, $q->left) && $this->isSameTree($p->right, $q->right);
602+
}
603+
}
604+
```
605+
569606
### **...**
570607

571608
```

solution/0100-0199/0100.Same Tree/README_EN.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,43 @@ impl Solution {
538538
}
539539
```
540540

541+
### **PHP**
542+
543+
```php
544+
/**
545+
* Definition for a binary tree node.
546+
* class TreeNode {
547+
* public $val = null;
548+
* public $left = null;
549+
* public $right = null;
550+
* function __construct($val = 0, $left = null, $right = null) {
551+
* $this->val = $val;
552+
* $this->left = $left;
553+
* $this->right = $right;
554+
* }
555+
* }
556+
*/
557+
class Solution {
558+
/**
559+
* @param TreeNode $p
560+
* @param TreeNode $q
561+
* @return Boolean
562+
*/
563+
function isSameTree($p, $q) {
564+
if ($p == Null && $q == Null) {
565+
return true;
566+
}
567+
if ($p == Null || $q == Null) {
568+
return false;
569+
}
570+
if ($p->val != $q->val) {
571+
return false;
572+
}
573+
return $this->isSameTree($p->left, $q->left) && $this->isSameTree($p->right, $q->right);
574+
}
575+
}
576+
```
577+
541578
### **...**
542579

543580
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* class TreeNode {
4+
* public $val = null;
5+
* public $left = null;
6+
* public $right = null;
7+
* function __construct($val = 0, $left = null, $right = null) {
8+
* $this->val = $val;
9+
* $this->left = $left;
10+
* $this->right = $right;
11+
* }
12+
* }
13+
*/
14+
class Solution {
15+
/**
16+
* @param TreeNode $p
17+
* @param TreeNode $q
18+
* @return Boolean
19+
*/
20+
function isSameTree($p, $q) {
21+
if ($p == Null && $q == Null) {
22+
return true;
23+
}
24+
if ($p == Null || $q == Null) {
25+
return false;
26+
}
27+
if ($p->val != $q->val) {
28+
return false;
29+
}
30+
return $this->isSameTree($p->left, $q->left) && $this->isSameTree($p->right, $q->right);
31+
}
32+
}

0 commit comments

Comments
 (0)