Skip to content
LC-2103 Easy LeetCode

2103. Rings and Rods

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 81% Topics: Hash Table, String
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

import collections


class Solution(object):
    def countPoints(self, rings):
        """
        :type rings: str
        :rtype: int
        """
        bits = {'R':0b001, 'G':0b010, 'B':0b100}
        rods = collections.defaultdict(int)
        for i in xrange(0, len(rings), 2):
            rods[int(rings[i+1])] |= bits[rings[i]]
        return sum(x == 0b111 for x in rods.itervalues())

Solution from kamyu104/LeetCode-Solutions · MIT