Skip to content

Commit 1c63922

Browse files
committed
3174
1 parent e09f23a commit 1c63922

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
class Solution
3+
{
4+
/**
5+
* @param String $s
6+
* @return String
7+
*/
8+
public function clearDigits($s)
9+
{
10+
$stack = [];
11+
12+
for ($i = 0; $i < strlen($s); $i++) {
13+
if (ctype_digit($s[$i])) {
14+
if (! empty($stack)) {
15+
array_pop($stack);
16+
}
17+
} else {
18+
$stack[] = $s[$i];
19+
}
20+
}
21+
return implode("", $stack);
22+
}
23+
}
24+
25+
$solution = new Solution();
26+
27+
echo $solution->clearDigits('cb34');

0 commit comments

Comments
 (0)