-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1249.php
More file actions
33 lines (32 loc) · 777 Bytes
/
1249.php
File metadata and controls
33 lines (32 loc) · 777 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
<?php
class Solution
{
function minRemoveToMakeValid($s)
{
$len=strlen($s);
$parenthesis=[];
for ($i=0; $i <$len ; $i++) {
if($s[$i]=='('){
array_push($parenthesis,$i);
}
else if($s[$i] == ')'){
if(count($parenthesis)>0){
array_pop($parenthesis);
}
else {
$s[$i]='#';
}
}
}
for ($i=0; $i <count($parenthesis) ; $i++) {
$s[$parenthesis[$i]]='#';
}
return $s;
// return str_replace('#','',$s);
}
}
$obj=new Solution();
$s= "))(()"; // "a(b(c)d)" ((())
echo "<pre>";
print_r($obj->minRemoveToMakeValid($s));
echo"</pre>";