From 646040b73df205a6522b1ee6922ba83a0cbe8c9d Mon Sep 17 00:00:00 2001 From: Dale Seo Date: Sun, 31 Aug 2025 10:15:12 -0400 Subject: [PATCH] valid-parentheses --- valid-parentheses/DaleSeo.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 valid-parentheses/DaleSeo.rs diff --git a/valid-parentheses/DaleSeo.rs b/valid-parentheses/DaleSeo.rs new file mode 100644 index 000000000..0ea456041 --- /dev/null +++ b/valid-parentheses/DaleSeo.rs @@ -0,0 +1,27 @@ +impl Solution { + pub fn is_valid(s: String) -> bool { + let mut stack = Vec::new(); + for ch in s.chars() { + match ch { + '(' | '{' | '[' => stack.push(ch), + ')' => { + if stack.pop() != Some('(') { + return false; + } + } + ']' => { + if stack.pop() != Some('[') { + return false; + } + } + '}' => { + if stack.pop() != Some('{') { + return false; + } + } + _ => return false, + } + } + stack.is_empty() + } +}