LeetCode 1904: The Number of Full Rounds You Have Played Solution
Master LeetCode problem 1904 (The Number of Full Rounds You Have Played), a medium challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.
Problem Explanation
Explanation
To solve this problem, we need to determine the number of full chess rounds played between the given login and logout times. We can do this by first converting the times to minutes since the start of the day (00:00) and then calculating the number of full rounds completed within that time frame.
- Convert the loginTime and logoutTime to total minutes since the start of the day.
- Calculate the starting full round after loginTime and the ending full round before logoutTime.
- Calculate the number of full rounds played.
Time Complexity: O(1) Space Complexity: O(1)
Solution Code
class Solution {
public int numberOfRounds(String startTime, String finishTime) {
int startMinutes = Integer.parseInt(startTime.substring(0, 2)) * 60 + Integer.parseInt(startTime.substring(3));
int finishMinutes = Integer.parseInt(finishTime.substring(0, 2)) * 60 + Integer.parseInt(finishTime.substring(3));
if (finishMinutes < startMinutes) {
finishMinutes += 24 * 60; // add 24 hours in minutes
}
int startRound = (startMinutes + 14) / 15 * 15; // starting full round after loginTime
int endRound = finishMinutes / 15 * 15; // ending full round before logoutTime
return Math.max(0, (endRound - startRound) / 15);
}
}Try It Yourself
Loading code editor...
Related LeetCode Problems
Frequently Asked Questions
How to solve LeetCode 1904 (The Number of Full Rounds You Have Played)?
This page provides optimized solutions for LeetCode problem 1904 (The Number of Full Rounds You Have Played) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.
What is the time complexity of LeetCode 1904 (The Number of Full Rounds You Have Played)?
The time complexity for LeetCode 1904 (The Number of Full Rounds You Have Played) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.
Can I run code for LeetCode 1904 on DevExCode?
Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 1904 in Java, C++, or Python.