728x90
https://leetcode.com/problems/rings-and-rods/
class Solution:
def countPoints(self, rings: str) -> int:
rods = { # ["R", "G", "B"]
"0":[False, False, False],
"1":[False, False, False],
"2":[False, False, False],
"3":[False, False, False],
"4":[False, False, False],
"5":[False, False, False],
"6":[False, False, False],
"7":[False, False, False],
"8":[False, False, False],
"9":[False, False, False]
}
ring_list = [rings[i:i+2] for i in range(0, len(rings), 2)]
for ring in ring_list:
if ring[0] == "R":
rods[ring[1]][0] = True
elif ring[0] == "G":
rods[ring[1]][1] = True
elif ring[0] == "B":
rods[ring[1]][2] = True
count = 0
for key, value in rods.items():
if value == [True, True, True]:
count += 1
return count
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 2657. Find the Prefix Common Array of Two Arrays (1) | 2024.02.28 |
---|---|
[Leetcode] 2744. Find Maximum Number of String Pairs (0) | 2024.02.26 |
[Leetcode] 1347. Minimum Number of Steps to Make Two Strings Anagram (1) | 2024.02.24 |
[Leetcode] 2913. Subarrays Distinct Element Sum of Squares I (0) | 2024.02.24 |
[Leetcode] 2956. Find Common Elements Between Two Arrays (0) | 2024.02.23 |