#20.Valid Parenthesis [LeetCode Grind 75 in Rust]

[Problem Link] https://leetcode.com/problems/valid-parentheses/

impl Solution {
    pub fn is_valid(s: String) -> bool {
        let mut ans: bool = false;
        let mut char_par_stack = vec![];

        for c in s.chars() {
            match c {
                '(' | '{' | '[' => char_par_stack.push(c),
                ')' | '}' | ']' => {
                    if char_par_stack.is_empty() {
                        return ans;
                    }

                    let top = char_par_stack.pop();
                    match top {
                        Some(top_ch) => {
                            match (top_ch, c) {
                                ('(',')') | ('{','}') | ('[',']') => continue,
                                _ => return ans,
                            }
                        },
                        None => return ans,
                    }

                },
                _ => return ans,
            }
        }

        if char_par_stack.is_empty() {
            ans = true;
        }
        return ans;

    }
}