Simple, easy to understand. And with Explanation
Intuition\n Describe your first thoughts on how to solve this problem. \nI reference from Uncle_John\'s code. He made a great code but didn\'t made any comment.
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI reference from Uncle_John\'s code. He made a great code but didn\'t made any comment.\nLet me make comment here.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst, we have convert targetSeconds into mins and secs, and beware once min > 100, it have to force +60 secs due to its\' check program.\nFrom here,there are 2 types of input in this question\n1. With minutes, and seconds >= 40\n2. With minutes, but sceonds < 40, which means we can minutes sub 1, and move 1 minutes to secs. Ex: 3:39 = 2:99, 1:20 = 80(sec)\nRest of things is value conver to_string. Checck if minute present, and check if second below 10 needs add char 0 befoe it.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int ToCheckCost(int start, int mc, int pc, string ts){\n      int res = 0;\n      if (ts.length() == 0) return INT_MAX;\n      for(char aa : ts){\n        if (aa - \'0\' != start){\n          res += mc + pc;\n          start = aa - \'0\';\n        }\n        else{\n          res += pc;\n        }\n      }\n      return res;\n    }\n    int minCostSetTime(int startAt, int moveCost, int pushCost, int targetSeconds) {\n        int min = targetSeconds / 60;\n        int sec = targetSeconds % 60;\n        if (min >= 100){\n          min -= 1;\n          sec += 60;\n        }\n        string str1, str2;\n        //str1\n        if (min){\n          if (sec >= 10){\n            str1 = to_string(min) + to_string(sec);\n          }else{\n            str1 = to_string(min) + "0" + to_string(sec);\n          }\n        }else{\n          str1 = to_string(sec);\n        }\n        //str2\n        if ((min) && (sec < 40))\n        {\n          if (min == 1){\n            str2 = to_string(sec + 60);\n          }else{\n            str2 = to_string(min-1) + to_string(sec+60);\n          }\n        }\n        //\n        int r1 = ToCheckCost(startAt, moveCost, pushCost, str1);\n        int r2 = ToCheckCost(startAt, moveCost, pushCost, str2);\n        return std::min(r1, r2);\n    }\n};\n```
['C++']