<?phpclass Solution { public $list = []; public function generateParenthesis($n) { $this->_gen(0, 0, $n, ''); return $this->list; } private function _gen($left, $right, $num, $result) { echo $left . ' ' . $right . "\t"; if ($left == $num && $right == $num) { array_push($this->list, $result); return; } if ($left < $num) { $this->_gen($left + 1, $right, $num, $result . '('); } if ($right < $num && $left > $right) { $this->_gen($left, $right + 1, $num, $result . ')'); } return; }}$cls = new Solution();$r = $cls->generateParenthesis(3);print_r($r);