Skip to content

Commit cb30881

Browse files
committed
Add solution for Goal Parser Interpretation problem
1 parent 1f59980 commit cb30881

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
class Solution
3+
{
4+
/**
5+
* @param String $command
6+
* @return String
7+
*/
8+
public function interpret($command)
9+
{
10+
$result = '';
11+
12+
$length = strlen($command);
13+
14+
for ($i = 0; $i < $length; $i++) {
15+
if ($command[$i] === 'G') {
16+
$result .= 'G';
17+
} elseif ($command[$i] === '(') {
18+
if ($command[$i + 1] === ')') {
19+
$result .= 'o';
20+
$i++;
21+
} else {
22+
$result .= 'al';
23+
$i += 3;
24+
}
25+
}
26+
}
27+
return $result;
28+
}
29+
}
30+
// Example usage:
31+
$solution = new Solution();
32+
echo $solution->interpret("G()(al)") . "\n";

0 commit comments

Comments
 (0)