File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
solution/2400-2499/2437.Number of Valid Clock Times Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -153,7 +153,29 @@ func countTime(time string) int {
153
153
### ** TypeScript**
154
154
155
155
``` ts
156
+ function countTime(time : string ): number {
157
+ let [hh, mm] = time .split (' :' );
158
+ return count (hh , 24 ) * count (mm , 60 );
159
+ };
156
160
161
+ function count(str : string , limit : number ): number {
162
+ let [a, b] = str .split (' ' ).map (d => Number (d ));
163
+ let ans = 0 ;
164
+ if (isNaN (a ) && isNaN (b )) return limit ;
165
+ if (isNaN (a )) {
166
+ for (let i = 0 ; i <= 9 ; i ++ ) {
167
+ if (i * 10 + b < limit ) ans ++ ;
168
+ }
169
+ return ans ;
170
+ }
171
+ if (isNaN (b )) {
172
+ for (let i = 0 ; i <= 9 ; i ++ ) {
173
+ if (a * 10 + i < limit ) ans ++ ;
174
+ }
175
+ return ans ;
176
+ }
177
+ return 1 ;
178
+ }
157
179
```
158
180
159
181
### ** ...**
Original file line number Diff line number Diff line change @@ -140,7 +140,29 @@ func countTime(time string) int {
140
140
### ** TypeScript**
141
141
142
142
``` ts
143
+ function countTime(time : string ): number {
144
+ let [hh, mm] = time .split (' :' );
145
+ return count (hh , 24 ) * count (mm , 60 );
146
+ };
143
147
148
+ function count(str : string , limit : number ): number {
149
+ let [a, b] = str .split (' ' ).map (d => Number (d ));
150
+ let ans = 0 ;
151
+ if (isNaN (a ) && isNaN (b )) return limit ;
152
+ if (isNaN (a )) {
153
+ for (let i = 0 ; i <= 9 ; i ++ ) {
154
+ if (i * 10 + b < limit ) ans ++ ;
155
+ }
156
+ return ans ;
157
+ }
158
+ if (isNaN (b )) {
159
+ for (let i = 0 ; i <= 9 ; i ++ ) {
160
+ if (a * 10 + i < limit ) ans ++ ;
161
+ }
162
+ return ans ;
163
+ }
164
+ return 1 ;
165
+ }
144
166
```
145
167
146
168
### ** ...**
Original file line number Diff line number Diff line change
1
+ function countTime ( time : string ) : number {
2
+ let [ hh , mm ] = time . split ( ':' ) ;
3
+ return count ( hh , 24 ) * count ( mm , 60 ) ;
4
+ } ;
5
+
6
+ function count ( str : string , limit : number ) : number {
7
+ let [ a , b ] = str . split ( '' ) . map ( d => Number ( d ) ) ;
8
+ let ans = 0 ;
9
+ if ( isNaN ( a ) && isNaN ( b ) ) return limit ;
10
+ if ( isNaN ( a ) ) {
11
+ for ( let i = 0 ; i <= 9 ; i ++ ) {
12
+ if ( i * 10 + b < limit ) ans ++ ;
13
+ }
14
+ return ans ;
15
+ }
16
+ if ( isNaN ( b ) ) {
17
+ for ( let i = 0 ; i <= 9 ; i ++ ) {
18
+ if ( a * 10 + i < limit ) ans ++ ;
19
+ }
20
+ return ans ;
21
+ }
22
+ return 1 ;
23
+ }
You can’t perform that action at this time.
0 commit comments