September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,14 +1,14 @@
|
|||
func balanced (str) {
|
||||
|
||||
var depth = 0;
|
||||
var depth = 0
|
||||
str.each { |c|
|
||||
if(c=='['){ ++depth }
|
||||
elsif(c==']'){ --depth < 0 && return false }
|
||||
};
|
||||
}
|
||||
|
||||
return !depth;
|
||||
return !depth
|
||||
}
|
||||
|
||||
[']','[','[[]','][]','[[]]','[[]]]][][]]','x[ y [ [] z ]][ 1 ][]abcd'].each { |str|
|
||||
printf("%sbalanced\t: %s\n", balanced(str) ? "" : "NOT ", str);
|
||||
};
|
||||
for str [']','[','[[]','][]','[[]]','[[]]]][][]]','x[ y [ [] z ]][ 1 ][]abcd'] {
|
||||
printf("%sbalanced\t: %s\n", balanced(str) ? "" : "NOT ", str)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue