[Python] Be careful with some annoying edge cases.
Convert targetseconds to mm:ss first.\nWe need to consider at most two cases:\n- If mm < 100, we should consider the cost of mm:ss.\n- If the current mm > 1 and
Convert targetseconds to **mm:ss** first.\nWe need to consider at most two cases:\n- If **mm < 100**, we should consider the cost of **mm:ss**.\n- If the current **mm > 1** and **ss < 40**, meaning we should consider the cost of **mm-1:ss+60**.\n\nWe should also be careful of the string of seconds:\n- If **mm > 0**, then ss **must** have a length of 2. For example, **7** should be written as **07**.\n- If **mm = 0**, then ss can have length of 1.\n\nThen we just iterate over the string of **mmss** and calculate the total costs.\n\n**Python**\n```\ndef minCostSetTime(self, start: int, mC: int, pC: int, TS: int) -> int:\n        def helper(mins, secs):\n            pre, cost, ss = str(start), 0, str(secs)\n            if mins != 0:\n                if len(ss) < 2:\n                    ss = "0" + ss\n                ss = str(mins) + ss            \n            for ch in ss:\n                if ch != pre:\n                    cost += mC\n                cost += pC\n                pre = ch\n            return cost\n\n        mins, secs = divmod(TS, 60)\n        ans = math.inf\n        \n        if mins < 100:\n            ans = min(ans, helper(mins, secs))\n        if secs < 40:\n            ans = min(ans, helper(mins - 1, secs + 60))\n        return ans\n```
[]