Skip to content

feat: add php solution to lc problem: No.0100 #932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions solution/0100-0199/0100.Same Tree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,43 @@ impl Solution {
}
```

### **PHP**

```php
/**
* Definition for a binary tree node.
* class TreeNode {
* public $val = null;
* public $left = null;
* public $right = null;
* function __construct($val = 0, $left = null, $right = null) {
* $this->val = $val;
* $this->left = $left;
* $this->right = $right;
* }
* }
*/
class Solution {
/**
* @param TreeNode $p
* @param TreeNode $q
* @return Boolean
*/
function isSameTree($p, $q) {
if ($p == Null && $q == Null) {
return true;
}
if ($p == Null || $q == Null) {
return false;
}
if ($p -> val != $q -> val) {
return false;
}
return $this -> isSameTree($p -> left, $q -> left) && $this -> isSameTree($p -> right, $q -> right);
}
}
```

### **...**

```
Expand Down
37 changes: 37 additions & 0 deletions solution/0100-0199/0100.Same Tree/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,43 @@ impl Solution {
}
```

### **PHP**

```php
/**
* Definition for a binary tree node.
* class TreeNode {
* public $val = null;
* public $left = null;
* public $right = null;
* function __construct($val = 0, $left = null, $right = null) {
* $this->val = $val;
* $this->left = $left;
* $this->right = $right;
* }
* }
*/
class Solution {
/**
* @param TreeNode $p
* @param TreeNode $q
* @return Boolean
*/
function isSameTree($p, $q) {
if ($p == Null && $q == Null) {
return true;
}
if ($p == Null || $q == Null) {
return false;
}
if ($p -> val != $q -> val) {
return false;
}
return $this -> isSameTree($p -> left, $q -> left) && $this -> isSameTree($p -> right, $q -> right);
}
}
```

### **...**

```
Expand Down
32 changes: 32 additions & 0 deletions solution/0100-0199/0100.Same Tree/Solution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Definition for a binary tree node.
* class TreeNode {
* public $val = null;
* public $left = null;
* public $right = null;
* function __construct($val = 0, $left = null, $right = null) {
* $this->val = $val;
* $this->left = $left;
* $this->right = $right;
* }
* }
*/
class Solution {
/**
* @param TreeNode $p
* @param TreeNode $q
* @return Boolean
*/
function isSameTree($p, $q) {
if ($p == Null && $q == Null) {
return true;
}
if ($p == Null || $q == Null) {
return false;
}
if ($p -> val != $q -> val) {
return false;
}
return $this -> isSameTree($p -> left, $q -> left) && $this -> isSameTree($p -> right, $q -> right);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

虽然支持 $this -> propsName 这种写法,但推荐使用 $this->propsName 形式(箭头左右不加空白,可参考该文件 8~10 行注释)。

Suggested change
if ($p -> val != $q -> val) {
return false;
}
return $this -> isSameTree($p -> left, $q -> left) && $this -> isSameTree($p -> right, $q -> right);
if ($p->val != $q->val) {
return false;
}
return $this->isSameTree($p->left, $q->left) && $this->isSameTree($p->right, $q->right);

}
}