Browse Source

initial codewars submission

master
Jim Infield 3 years ago
parent
commit
fd7c58f8d1
  1. 24
      src/main.rs

24
src/main.rs

@ -2,19 +2,33 @@
fn main() {
let args = vec![
"string1",
"string2",
"(){}[]",
"([{}])",
"(}",
"[(])",
"[({})](]",
];
println!();
for arg in args {
println!("{}",func(&arg));
println!("{:8} => {}",arg, valid_braces(arg));
};
println!();
}
fn func(s: &str) -> String {
s.into()
fn valid_braces(s: &str) -> bool {
let mut v = vec![];
for c in s.chars() {
match c {
'('|'{'|'[' => v.push(c),
')' => if v.pop() != Some('(') { return false },
'}' => if v.pop() != Some('{') { return false },
']' => if v.pop() != Some('[') { return false },
_ => {},
}
}
v.is_empty()
}
Loading…
Cancel
Save