-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.rs
44 lines (38 loc) · 1.15 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() {
println!("Hello, world!");
}
struct Solution {}
impl Solution {
pub fn is_valid(s: String) -> bool {
let mut vec = vec![];
for c in s.chars() {
if c == '(' || c == '[' || c == '{' {
vec.push(c);
} else if c == ')' || c == ']' || c == '}' {
let o = vec.pop();
let out;
if let None = o { return false }
else { out = o.unwrap() }
if (out == '(' && c == ')') ||
(out == '[' && c == ']') ||
(out == '{' && c == '}') {
continue
} else { return false }
}
}
if vec.len() > 0 { false }
else { true }
}
}
#[cfg(test)]
mod test {
use crate::*;
#[test]
fn basic() {
assert_eq!(Solution::is_valid("([)]".to_string()), false);
assert_eq!(Solution::is_valid("{[]}".to_string()), true);
assert_eq!(Solution::is_valid("()[]{}".to_string()), true);
assert_eq!(Solution::is_valid("".to_string()), true);
assert_eq!(Solution::is_valid("[".to_string()), false);
}
}