Skip to content

1904. The Number of Full Rounds You Have Played 👎

  • Time: $O(1)$
  • Space: $O(1)$
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
class Solution {
 public:
  int numberOfRounds(string startTime, string finishTime) {
    const int start = getMinutes(startTime);
    int finish = getMinutes(finishTime);
    if (start > finish)
      finish += 60 * 24;
    return max(0, finish / 15 - (start + 14) / 15);
  }

 private:
  int getMinutes(const string& s) {
    return 60 * stoi(s.substr(0, 2)) + stoi(s.substr(3));
  }
};
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
class Solution {
  public int numberOfRounds(String startTime, String finishTime) {
    final int start = getMinutes(startTime);
    int finish = getMinutes(finishTime);
    if (start > finish)
      finish += 60 * 24;
    return Math.max(0, finish / 15 - (start + 14) / 15);
  }

  private int getMinutes(final String s) {
    return 60 * Integer.valueOf(s.substring(0, 2)) + Integer.valueOf(s.substring(3));
  }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class Solution:
  def numberOfRounds(self, startTime: str, finishTime: str) -> int:
    def getMinutes(s: str) -> int:
      return 60 * int(s[:2]) + int(s[3:])

    start = getMinutes(startTime)
    finish = getMinutes(finishTime)
    if start > finish:
      finish += 60 * 24

    return max(0, finish // 15 - (start + 14) // 15)
Back to top