Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
void main() {
isProperlyNested(String str) {
var splittedString = str.split("");
List outputs = [];
for (var i = 0; i < str.length; i++) {
var currentVal = str[i];
if (currentVal == '{' || currentVal == '(' || currentVal == '[') {
outputs.add(currentVal);
} else if (currentVal == '}' || currentVal == ')' || currentVal == ']') {
var t = outputs.removeLast() + currentVal;
if (t != "{}" && t != "()" && t != "[]") return 'Not properly nested';
} else {
return 'Not properly nested';
}
}
if (outputs.isNotEmpty) {
return 'Not properly nested';
} else {
return 'String is properly nested';
}
}
print(isProperlyNested("(){){("));
print(isProperlyNested("({[]})"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment