9 lines
181 B
Perl
9 lines
181 B
Perl
|
|
sub balanced {
|
||
|
|
my $depth = 0;
|
||
|
|
for (split //, shift) {
|
||
|
|
if ($_ eq '[') { ++$depth }
|
||
|
|
elsif ($_ eq ']') { return if --$depth < 0 }
|
||
|
|
}
|
||
|
|
return !$depth
|
||
|
|
}
|