- 在run-tests.php中为数字文件名添加'app_'前缀以避免命名冲突 - 在Translator.php中为数字目标名称添加'app_'前缀以确保有效标识符 - 重构NativeCallToCDecl函数中的参数列表构建逻辑,调整代码顺序以提高可读性 - 添加测试用例验证岛屿周长计算算法的正确性pull/1/head
parent
92bd1fe56c
commit
d81c4cda62
3 changed files with 63 additions and 5 deletions
@ -0,0 +1,52 @@ |
||||
--TEST-- |
||||
mixed/1.phpt |
||||
--FILE-- |
||||
<?php |
||||
|
||||
class Solution |
||||
{ |
||||
protected $grid; |
||||
public $result = 0; |
||||
|
||||
public function __construct(array $grid) |
||||
{ |
||||
$this->grid = $grid; |
||||
$this->islandPerimeter(); |
||||
} |
||||
|
||||
public function islandPerimeter() |
||||
{ |
||||
if (empty($this->grid) || empty($this->grid[0])) return 0; |
||||
|
||||
foreach ($this->grid as $key => $val) { |
||||
|
||||
foreach ($this->grid[0] as $k => $v) { |
||||
if ($this->grid[$key][$k] == 0) continue; |
||||
$this->result += 4; |
||||
|
||||
if ($key > 0 && $this->grid[$key - 1][$k] == 1) { |
||||
$this->result -= 2; |
||||
} |
||||
if ($k > 0 && $this->grid[$key][$k - 1] == 1) { |
||||
$this->result -= 2; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
$arr = [ |
||||
[0, 1, 0, 0], |
||||
[1, 1, 1, 0], |
||||
[0, 1, 0, 0], |
||||
[1, 1, 0, 0] |
||||
]; |
||||
|
||||
$result = new Solution($arr); |
||||
var_dump($result->result); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
int(16) |
||||
Loading…
Reference in new issue