1 Star 0 Fork 1

hesuyang/php-leetcode

forked from shyiran/php-leetcode 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
leetcode-0101-symmetric-tree.php 827 Bytes
一键复制 编辑 原始数据 按行查看 历史
shyiran 提交于 2022-12-12 20:57 +08:00 . 补充
/**
* 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 $root
* @return Boolean
*/
function checktree($root1,$root2){
if($root1 == null && $root2 == null) return true;
if($root1 == null || $root2 == null) return false;
return ($root1->val == $root2->val)
&&$this->checktree($root1->right,$root2->left)
&&$this->checktree($root1->left,$root2->right);
}
function isSymmetric($root) {
return $this->checktree($root,$root);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/hesuyang/php-leetcode.git
git@gitee.com:hesuyang/php-leetcode.git
hesuyang
php-leetcode
php-leetcode
master

搜索帮助