思路:
转换成分钟,方便计算。
实现:
1 class Solution 2 { 3 public: 4 int numberOfRounds(string startTime, string finishTime) 5 { 6 int x = stoi(startTime.substr(0, 2)) * 60 + stoi(startTime.substr(3, 2)); 7 int y = stoi(finishTime.substr(0, 2)) * 60 + stoi(finishTime.substr(3, 2)); 8 if (y < x) y += 24 * 60; 9 y = y / 15 * 15; 10 return max(0, (y - x)) / 15; 11 } 12 };