| 4 | |
| 5 | impl Solution { |
| 6 | pub fn count_points(rings: String) -> i32 { |
| 7 | use std::collections::HashSet; |
| 8 | |
| 9 | let mut red: HashSet<char> = HashSet::new(); |
| 10 | let mut green: HashSet<char> = HashSet::new(); |
| 11 | let mut blue: HashSet<char> = HashSet::new(); |
| 12 | let limit_index = &rings.len() / 2; |
| 13 | let rings_chars: Vec<char> = rings.chars().collect(); |
| 14 | for i in 0..limit_index { |
| 15 | if rings_chars[2*i] == 'R' { |
| 16 | red.insert(rings_chars[2*i+1]); |
| 17 | } |
| 18 | if rings_chars[2*i] == 'G' { |
| 19 | green.insert(rings_chars[2*i+1]); |
| 20 | } |
| 21 | if rings_chars[2*i] == 'B' { |
| 22 | blue.insert(rings_chars[2*i+1]); |
| 23 | } |
| 24 | } |
| 25 | let mid: HashSet<_> = red.intersection(&green).collect(); |
| 26 | let mut mid_res: HashSet<char> = HashSet::new(); |
| 27 | for e in mid { |
| 28 | mid_res.insert(*e); |
| 29 | } |
| 30 | let res = blue.intersection(&mid_res); |
| 31 | res.count() as i32 |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | fn main() { |