题目
解法:greedy
- 把时间转化为分钟
- 计算出time difference
- 从60开始从大到小依次计算每个increase可以最多取多少步
class Solution:def convertTime(self, current: str, correct: str) -> int:curr_h,curr_m = int(current.split(':')[0]),int(current.split(':')[1])unix_curr = curr_h * 60 + curr_mcorr_h,corr_m = int(correct.split(':')[0]),int(correct.split(':')[1])unix_corr = corr_h * 60 + corr_m# print(unix_curr,unix_corr)diff = unix_corr - unix_currnum1,remain1 = diff // 60, diff % 60num2,remain2 = remain1 // 15, remain1 % 15num3,remain3 = remain2 // 5, remain2 % 5res = num1 + num2 + num3 + remain3return res
时间复杂度:常数
空间复杂度:常数