-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path391.php
58 lines (57 loc) · 1.81 KB
/
391.php
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
class Solution
{
/**
* @param Integer[][] $rectangles
* @return Boolean
*/
public function isRectangleCover($rectangles)
{
$bls = [];
$brs = [];
$tls = [];
$trs = [];
foreach ($rectangles as $rectangle) {
$bl = sprintf('%d-%d', $rectangle[0], $rectangle[1]);
$br = sprintf('%d-%d', $rectangle[2], $rectangle[1]);
$tl = sprintf('%d-%d', $rectangle[0], $rectangle[3]);
$tr = sprintf('%d-%d', $rectangle[2], $rectangle[3]);
if (array_key_exists($bl, $bls) || array_key_exists($br, $brs) || array_key_exists($tl,
$tls) || array_key_exists($tr, $trs)) {
return false;
}
if (array_key_exists($bl, $brs)) {
unset($brs[$bl]);
} elseif (array_key_exists($bl, $tls)) {
unset($tls[$bl]);
} else {
$bls[$bl] = 1;
}
if (array_key_exists($br, $bls)) {
unset($bls[$br]);
} elseif (array_key_exists($br, $trs)) {
unset($trs[$br]);
} else {
$brs[$br] = 1;
}
if (array_key_exists($tl, $bls)) {
unset($bls[$tl]);
} elseif (array_key_exists($tl, $trs)) {
unset($trs[$tl]);
} else {
$tls[$tl] = 1;
}
if (array_key_exists($tr, $tls)) {
unset($tls[$tr]);
} elseif (array_key_exists($tr, $brs)) {
unset($brs[$tr]);
} else {
$trs[$tr] = 1;
}
}
if (count($bls) !== 1 || count($brs) !== 1 || count($tls) !== 1 || count($trs) !== 1) {
return false;
}
return true;
}
}