File tree 4 files changed +29
-53
lines changed
solution/1900-1999/1904.The Number of Full Rounds You Have Played
4 files changed +29
-53
lines changed Original file line number Diff line number Diff line change @@ -105,29 +105,21 @@ class Solution {
105
105
}
106
106
```
107
107
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**
119
109
110
+ ``` ts
111
+ function numberOfRounds(startTime : string , finishTime : string ): number {
112
+ let m1 = toMinutes (startTime ), m2 = toMinutes (finishTime );
120
113
if (m1 > m2 ) {
121
114
m2 += 24 * 60 ;
122
115
}
123
-
124
116
let ans = Math .floor (m2 / 15 ) - Math .ceil (m1 / 15 );
125
- return ans < 0 ? 0 : ans ;
117
+ return ans > 0 ? ans : 0 ;
126
118
};
127
119
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 ;
131
123
}
132
124
```
133
125
Original file line number Diff line number Diff line change @@ -93,29 +93,21 @@ class Solution {
93
93
}
94
94
```
95
95
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**
107
97
98
+ ``` ts
99
+ function numberOfRounds(startTime : string , finishTime : string ): number {
100
+ let m1 = toMinutes (startTime ), m2 = toMinutes (finishTime );
108
101
if (m1 > m2 ) {
109
102
m2 += 24 * 60 ;
110
103
}
111
-
112
104
let ans = Math .floor (m2 / 15 ) - Math .ceil (m1 / 15 );
113
- return ans < 0 ? 0 : ans ;
105
+ return ans > 0 ? ans : 0 ;
114
106
};
115
107
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 ;
119
111
}
120
112
```
121
113
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments