-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path455.php
More file actions
36 lines (32 loc) · 726 Bytes
/
455.php
File metadata and controls
36 lines (32 loc) · 726 Bytes
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
<?php
class Solution {
/**
* @param Integer[] $g
* @param Integer[] $s
* @return Integer
*/
function findContentChildren($g, $s)
{
if (empty($s) || empty($g)) return 0;
sort($g);
sort($s);
$num = 0;
foreach ($g as $v) {
$num1 = 0;
foreach ($s as $k => $v1) {
if ($v1 >= $v) {
$num1 ++;
unset($s[$k]);
break;
}
}
$num += $num1;
if ($num1 == 0 || empty($s)) return $num;
}
return $num;
}
}
$sol = new Solution();
$g= [1,2,3];
$s = [3];
var_dump($sol->findContentChildren($g, $s));