diff --git a/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README.md b/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README.md index 33e0c86af993c..2df2ecc8331e0 100644 --- a/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README.md +++ b/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README.md @@ -115,15 +115,14 @@ class Solution { * @return {number} */ var numberOfRounds = function(startTime, finishTime) { - let p1 = Math.ceil(toMinutes(startTime) / 15); - let p2 = Math.floor(toMinutes(finishTime) / 15); + let m1 = toMinutes(startTime), m2 = toMinutes(finishTime); - if (p1 > p2) { - p2 += 24 * 60 / 15; + if (m1 > m2) { + m2 += 24 * 60; } - let ans = p2 - p1; - return ans; + let ans = Math.floor(m2 / 15) - Math.ceil(m1 / 15); + return ans < 0 ? 0 : ans; }; function toMinutes(time) { diff --git a/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README_EN.md b/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README_EN.md index 5d6a55d4cece9..0227064b1758f 100644 --- a/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README_EN.md +++ b/solution/1900-1999/1904.The Number of Full Rounds You Have Played/README_EN.md @@ -103,15 +103,14 @@ class Solution { * @return {number} */ var numberOfRounds = function(startTime, finishTime) { - let p1 = Math.ceil(toMinutes(startTime) / 15); - let p2 = Math.floor(toMinutes(finishTime) / 15); + let m1 = toMinutes(startTime), m2 = toMinutes(finishTime); - if (p1 > p2) { - p2 += 24 * 60 / 15; + if (m1 > m2) { + m2 += 24 * 60; } - let ans = p2 - p1; - return ans; + let ans = Math.floor(m2 / 15) - Math.ceil(m1 / 15); + return ans < 0 ? 0 : ans; }; function toMinutes(time) { diff --git a/solution/1900-1999/1904.The Number of Full Rounds You Have Played/Solution.js b/solution/1900-1999/1904.The Number of Full Rounds You Have Played/Solution.js index b0bb5a7ca3c9b..14edde37e6581 100644 --- a/solution/1900-1999/1904.The Number of Full Rounds You Have Played/Solution.js +++ b/solution/1900-1999/1904.The Number of Full Rounds You Have Played/Solution.js @@ -4,15 +4,14 @@ * @return {number} */ var numberOfRounds = function(startTime, finishTime) { - let p1 = Math.ceil(toMinutes(startTime) / 15); - let p2 = Math.floor(toMinutes(finishTime) / 15); + let m1 = toMinutes(startTime), m2 = toMinutes(finishTime); - if (p1 > p2) { - p2 += 24 * 60 / 15; + if (m1 > m2) { + m2 += 24 * 60; } - let ans = p2 - p1; - return ans; + let ans = Math.floor(m2 / 15) - Math.ceil(m1 / 15); + return ans < 0 ? 0 : ans; }; function toMinutes(time) {