Skip to content

Commit e36ae40

Browse files
committed
feat: add typescript solution to lc problem: No.1904
No.1904.The Number of Full Rounds You Have Played
1 parent 2aaf40e commit e36ae40

File tree

4 files changed

+29
-53
lines changed

4 files changed

+29
-53
lines changed

solution/1900-1999/1904.The Number of Full Rounds You Have Played/README.md

+8-16
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,21 @@ class Solution {
105105
}
106106
```
107107

108-
### **JavaScript**
109-
110-
```js
111-
/**
112-
* @param {string} startTime
113-
* @param {string} finishTime
114-
* @return {number}
115-
*/
116-
var numberOfRounds = function (startTime, finishTime) {
117-
let m1 = toMinutes(startTime),
118-
m2 = toMinutes(finishTime);
108+
### **TypeScript**
119109

110+
```ts
111+
function numberOfRounds(startTime: string, finishTime: string): number {
112+
let m1 = toMinutes(startTime), m2 = toMinutes(finishTime);
120113
if (m1 > m2) {
121114
m2 += 24 * 60;
122115
}
123-
124116
let ans = Math.floor(m2 / 15) - Math.ceil(m1 / 15);
125-
return ans < 0 ? 0 : ans;
117+
return ans > 0 ? ans : 0;
126118
};
127119

128-
function toMinutes(time) {
129-
let [h, m] = time.split(":");
130-
return Number(h) * 60 + Number(m);
120+
function toMinutes(time: string): number {
121+
let [h, m] = time.split(":").map(Number);
122+
return h * 60 + m;
131123
}
132124
```
133125

solution/1900-1999/1904.The Number of Full Rounds You Have Played/README_EN.md

+8-16
Original file line numberDiff line numberDiff line change
@@ -93,29 +93,21 @@ class Solution {
9393
}
9494
```
9595

96-
### **JavaScript**
97-
98-
```js
99-
/**
100-
* @param {string} startTime
101-
* @param {string} finishTime
102-
* @return {number}
103-
*/
104-
var numberOfRounds = function (startTime, finishTime) {
105-
let m1 = toMinutes(startTime),
106-
m2 = toMinutes(finishTime);
96+
### **TypeScript**
10797

98+
```ts
99+
function numberOfRounds(startTime: string, finishTime: string): number {
100+
let m1 = toMinutes(startTime), m2 = toMinutes(finishTime);
108101
if (m1 > m2) {
109102
m2 += 24 * 60;
110103
}
111-
112104
let ans = Math.floor(m2 / 15) - Math.ceil(m1 / 15);
113-
return ans < 0 ? 0 : ans;
105+
return ans > 0 ? ans : 0;
114106
};
115107

116-
function toMinutes(time) {
117-
let [h, m] = time.split(":");
118-
return Number(h) * 60 + Number(m);
108+
function toMinutes(time: string): number {
109+
let [h, m] = time.split(":").map(Number);
110+
return h * 60 + m;
119111
}
120112
```
121113

solution/1900-1999/1904.The Number of Full Rounds You Have Played/Solution.js

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function numberOfRounds(startTime: string, finishTime: string): number {
2+
let m1 = toMinutes(startTime), m2 = toMinutes(finishTime);
3+
if (m1 > m2) {
4+
m2 += 24 * 60;
5+
}
6+
let ans = Math.floor(m2 / 15) - Math.ceil(m1 / 15);
7+
return ans > 0 ? ans : 0;
8+
};
9+
10+
function toMinutes(time: string): number {
11+
let [h, m] = time.split(":").map(Number);
12+
return h * 60 + m;
13+
}

0 commit comments

Comments
 (0)