파비의 매일매일 공부기록

2023.11.20 Today's Challenge 본문

Problem Solving/LeetCode

2023.11.20 Today's Challenge

fabichoi 2023. 11. 20. 23:45

https://leetcode.com/problems/minimum-amount-of-time-to-collect-garbage/

 

Minimum Amount of Time to Collect Garbage - LeetCode

Can you solve this real interview question? Minimum Amount of Time to Collect Garbage - You are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the ith house. garbage[i] consists only of the characters 'M

leetcode.com

너무 쓱- 봐서 그런가.. 무슨 문젠지 이해가 잘 안감 -_-;
여튼 해쉬 맵으로 푸는 문제!

class Solution:
    def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:
        result = sum(len(g) for g in garbage)
        g, p, m = False, False, False
        for i in range(len(travel), 0, -1):
            g |= 'G' in garbage[i]
            p |= 'P' in garbage[i]
            m |= 'M' in garbage[i]
            result += travel[i-1] * (g + p + m)        
        return result
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

2023.11.22 Today's Challenge  (0) 2023.11.22
2023.11.21 Today's Challenge  (0) 2023.11.21
2023.11.19 Today's Challenge  (0) 2023.11.19
2023.11.18 Today's Challenge  (0) 2023.11.18
2023.11.17 Today's Challenge  (0) 2023.11.17
Comments