Sha256: 2f59058fb1deb78a54fa066d2b3a335b95437209934cb967e6714f0603272804
Contents?: true
Size: 540 Bytes
Versions: 63
Compression:
Stored size: 540 Bytes
Contents
import ceylon.collection { ArrayList } Map<Character,Character> openFor = map { '}'->'{', ')'->'(', ']'->'[' }; Set<Character> opens = set(openFor.items); Boolean balanced(String brackets) { value expectedOpens = ArrayList<Character>(); for (c in brackets) { if (opens.contains(c)) { expectedOpens.push(c); } else if (exists open = openFor[c]) { if ((expectedOpens.pop() else '!') != open) { return false; } } } return expectedOpens.empty; }
Version data entries
63 entries across 63 versions & 1 rubygems