LeetCode solutions

2226. Rings and Rods

My accepted Python solution to LeetCode problem 2226, Rings and Rods, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.1MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.1MB, accepted 2025-12-29.

python
class Solution:
    def countPoints(self, rings: str) -> int:
        rods = [set() for _ in range(10)]
        
        for i in range(0, len(rings), 2):
            color = rings[i]
            rod = int(rings[i + 1])
            rods[rod].add(color)
        
        count = 0
        for rod in rods:
            if len(rod) == 3:
                count += 1
        return count

Source