Balanced brackets: Difference between revisions
Content deleted Content added
m →{{header|Sidef}}: code simplification |
|||
Line 4,087: | Line 4,087: | ||
str.each { |c| |
str.each { |c| |
||
if(c=='['){ depth++ } |
if(c=='['){ depth++ } |
||
elsif(c==']'){ depth-- < 0 && |
elsif(c==']'){ depth-- < 0 && return false } |
||
}; |
}; |
||
return |
return !depth; |
||
} |
} |
||
[']','[','[[]','][]','[[]]','[[]]]][][]]','x[ y [ [] z ]][ 1 ][]abcd'].each { |
[']','[','[[]','][]','[[]]','[[]]]][][]]','x[ y [ [] z ]][ 1 ][]abcd'].each { |str| |
||
⚫ | |||
|str| |
|||
⚫ | |||
⚫ | |||
⚫ | |||
'''Output:''' |
'''Output:''' |