MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / is_valid

Method is_valid

20. Valid Parentheses/src/main.rs:8–27  ·  view source on GitHub ↗
(s: String)

Source from the content-addressed store, hash-verified

6
7impl Solution {
8 pub fn is_valid(s: String) -> bool {
9 let mut vec = vec![];
10 for c in s.chars() {
11 if c == '(' || c == '[' || c == '{' {
12 vec.push(c);
13 } else if c == ')' || c == ']' || c == '}' {
14 let o = vec.pop();
15 let out;
16 if let None = o { return false }
17 else { out = o.unwrap() }
18 if (out == '(' && c == ')') ||
19 (out == '[' && c == ']') ||
20 (out == '{' && c == '}') {
21 continue
22 } else { return false }
23 }
24 }
25 if vec.len() > 0 { false }
26 else { true }
27 }
28}
29
30#[cfg(test)]

Callers

nothing calls this directly

Calls 2

pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected