PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function isBalanced(string $string): bool { $stack = []; $start = '('; $end = ')'; $length = strlen($string); for ($i = 0; $i < $length; $i++) { $current = $string[i]; if ($current === $start) { array_push($start, $stack); } elseif ($current === $end) { if (empty($stack)) { return false; } array_pop($stack); } } return empty($stack); } $t = isBalanced('((()))('); print_r($t);
Show:  
Copy Clear