MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / count_points

Method count_points

2103-rings-and-rods.rs:6–32  ·  view source on GitHub ↗
(rings: String)

Source from the content-addressed store, hash-verified

4
5impl 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
35fn main() {

Callers

nothing calls this directly

Calls 1

insertMethod · 0.80

Tested by

no test coverage detected