Leetcode 2226 Solution
This article provides solution to leetcode question 2226 (rings-and-rods)
Access this page by simply typing in "lcs 2226" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/rings-and-rods
Solution
class Solution:
def countPoints(self, rings: str) -> int:
masks = [0] * 10
i = 0
while i < len(rings):
color = rings[i]
rod = int(rings[i + 1])
if color == 'R':
color_index = 0
elif color == 'G':
color_index = 1
elif color == 'B':
color_index = 2
masks[rod] |= 1 << color_index
i += 2
ans = 0
for mask in masks:
if mask & 0b0111 == 0b0111:
ans += 1
return ans