Loading RustViz Engine...
Verify bracket matching for (), {}, and [] using a LIFO stack.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub fn is_valid(s: &str) -> bool {
let mut stack = Vec::new();
for c in s.chars() {
match c {
'(' => stack.push(')'),
'{' => stack.push('}'),
'[' => stack.push(']'),
')' | '}' | ']' => if stack.pop() != Some(c) { return false; },
_ => {}
}
}
stack.is_empty()
}