2103. Rings and Rods Easy
1/**
2 * [2103] Rings and Rods
3 *
4 * There are n rings and each ring is either red, green, or blue. The rings are distributed across ten rods labeled from 0 to 9.
5 * You are given a string rings of length 2n that describes the n rings that are placed onto the rods. Every two characters in rings forms a color-position pair that is used to describe each ring where:
6 *
7 * The first character of the i^th pair denotes the i^th ring's color ('R', 'G', 'B').
8 * The second character of the i^th pair denotes the rod that the i^th ring is placed on ('0' to '9').
9 *
10 * For example, "R3G2B1" describes n == 3 rings: a red ring placed onto the rod labeled 3, a green ring placed onto the rod labeled 2, and a blue ring placed onto the rod labeled 1.
11 * Return the number of rods that have all three colors of rings on them.
12 *
13 * Example 1:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2021/11/23/ex1final.png" style="width: 258px; height: 130px;" />
15 * Input: rings = "B0B6G0R6R0R6G9"
16 * Output: 1
17 * Explanation:
18 * - The rod labeled 0 holds 3 rings with all colors: red, green, and blue.
19 * - The rod labeled 6 holds 3 rings, but it only has red and blue.
20 * - The rod labeled 9 holds only a green ring.
21 * Thus, the number of rods with all three colors is 1.
22 *
23 * Example 2:
24 * <img alt="" src="https://assets.leetcode.com/uploads/2021/11/23/ex2final.png" style="width: 266px; height: 130px;" />
25 * Input: rings = "B0R0G0R9R0B0G0"
26 * Output: 1
27 * Explanation:
28 * - The rod labeled 0 holds 6 rings with all colors: red, green, and blue.
29 * - The rod labeled 9 holds only a red ring.
30 * Thus, the number of rods with all three colors is 1.
31 *
32 * Example 3:
33 *
34 * Input: rings = "G4"
35 * Output: 0
36 * Explanation:
37 * Only one ring is given. Thus, no rods have all three colors.
38 *
39 *
40 * Constraints:
41 *
42 * rings.length == 2 * n
43 * 1 <= n <= 100
44 * rings[i] where i is even is either 'R', 'G', or 'B' (0-indexed).
45 * rings[i] where i is odd is a digit from '0' to '9' (0-indexed).
46 *
47 */
48pub struct Solution {}
49
50// problem: https://leetcode.com/problems/rings-and-rods/
51// discuss: https://leetcode.com/problems/rings-and-rods/discuss/?currentPage=1&orderBy=most_votes&query=
52
53// submission codes start here
54
55impl Solution {
56 pub fn count_points(rings: String) -> i32 {
57 0
58 }
59}
60
61// submission codes end
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_2103() {
69 }
70}
71
Back
© 2025 bowen.ge All Rights Reserved.