2391. Minimum Amount of Time to Collect Garbage

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2391

class Solution:
    def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:
        def f(x: str) -> int:
            res = 0
            st = 0
            for i, s in enumerate(garbage):
                if t := s.count(x):
                    res += t + st
                    st = 0
                if i < len(travel):
                    st += travel[i]
            return res

        return f('M') + f('P') + f('G')