-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6020.php
More file actions
36 lines (32 loc) · 775 Bytes
/
Copy path6020.php
File metadata and controls
36 lines (32 loc) · 775 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
{
function divideArray($nums)
{
sort($nums);
$ans=[];
$paircount=0;
foreach ($nums as $value) {
if(count($ans)>0){
$temp=$ans[array_key_last($ans)];
if($temp==$value){
$paircount+=1;
array_pop($ans);
}
else{
array_push($ans,$value);
}
}
else{
array_push($ans,$value);
}
}
return $paircount>=(count($nums)/2)?true:false;
}
}
$obj = new Solution();
$pushed = [1, 2, 3, 4, 5];
// $pushed = [3, 2, 3, 2, 2, 2];
echo "<pre>";
print_r($obj->divideArray($pushed));
echo "</pre>";