2437. Number of Valid Clock Times
T: O(1)
S: O(1)
```java
class Solution {
public int countTime(String time) {
int result = 1;
char first = time.charAt(0);
char second = time.charAt(1);
char third = time.charAt(3);
char fourth = time.charAt(4);
if (first == '?' && second == '?') {
result *= 24;
} else {
if (first == '?') {
if ((second - '0') >= 4) {
result *= 2;
} else {
result *= 3;
}
} else if (second == '?' ) {
if (first == '0' || first == '1') {
result *= 10;
} else { // first = 2
result *= 4;
}
}
}
if (third == '?') {
result *= 6;
}
if (fourth == '?') {
result *= 10;
}
return result;
}
}
/**
??:??
"?5:00"
if second > 4
first can be 0 1
else 012
if second == ?
first can be 0 1 2
"x?:00"
if (first 0 or 1) ? = 0~9
2 => ? = 0~3
third ?
0~5
4th
0~9
23:59
19:59
09:59
*/
```
Last updated