2023-11-02发表2023-11-02更新LeetCode每日一题几秒读完 (大约85个字)0次访问2103. 环和杆2103. 环和杆 难度: easy 原始链接: https://leetcode.cn/problems/rings-and-rods 标签: 位运算 解法一: 位运算go1234567891011121314151617181920212223func countPoints(rings string) int { flag := 0 length := len(rings) for i := 1; i < length; i += 2 { shift := 0 if rings[i - 1] == 'R' { shift = 1 } else if rings[i - 1] == 'G' { shift = 1 << 1 } else if rings[i - 1] == 'B' { shift = 1 << 2 } flag |= shift << (int(rings[i] - '0') * 3) } ans := 0 for flag != 0 { if (flag & 7) == 7 { ans++ } flag >>= 3 } return ans} 2103. 环和杆https://wuhunyu.top/leetcode/2023/11/rings-and-rods/index.html作者wuhunyu发布于2023-11-02更新于2023-11-02许可协议#位运算