-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp.php
60 lines (57 loc) · 1.07 KB
/
exp.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
59
60
<?php
/*function solution($A){
$min = min($A);
$max = max($A);
if($min < -1000000 || $max > 1000000){
return "Melebihi Batas";
}
if($max < 0){
return 1;
}
if(gettype($A) != "array"){
return "Parameter harus array";
}
sort($A);
foreach (array_unique($A) as $k) {
if(gettype($k) != "integer"){
return "Array harus berisi number";
}
if($min != $k){
return $min;
}
$min++;
}
return $min;
}*/
function solution($A){
if(count($A) < 1 || count($A) >= 1000){
return "Jumlah array harus 1 - 1000";
}
$min = min($A);
$max = max($A);
if($min < -1000000 || $max > 1000000){
return "Melebihi Batas";
}
if(gettype($A) != "array"){
return "Parameter harus array";
}
$total = 0;
$count = 1;
foreach ($A as $k) {
if(gettype($k) != "integer"){
return "Array harus berisi number";
}
if ($count <= 3) {
if ($k > 0) {
$total += $k;
$count++;
}
}
}
return $total;
}
//manggil fungsi
//echo solution([-1,-3,6,-4,1,2]);
//echo solution([1,2,3]);
echo solution([]);
?>