Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,8 +1,5 @@
|
|||
use Regexp::Common 'balanced';
|
||||
my $re = qr/^$RE{balanced}{-parens=>'[]'}$/;
|
||||
sub balanced {
|
||||
my $depth = 0;
|
||||
for (split //, shift) {
|
||||
if ($_ eq '[') { ++$depth }
|
||||
elsif ($_ eq ']') { return if --$depth < 0 }
|
||||
}
|
||||
return !$depth
|
||||
return shift =~ $re;
|
||||
}
|
||||
|
|
|
|||
8
Task/Balanced-brackets/Perl/balanced-brackets-4.pl
Normal file
8
Task/Balanced-brackets/Perl/balanced-brackets-4.pl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
sub balanced {
|
||||
my $depth = 0;
|
||||
for (split //, shift) {
|
||||
if ($_ eq '[') { ++$depth }
|
||||
elsif ($_ eq ']') { return if --$depth < 0 }
|
||||
}
|
||||
return !$depth
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue