Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8cd8562

Browse files
authoredOct 15, 2022
Added solution for 2437
1 parent 03c5c9a commit 8cd8562

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
 

‎02437. Number of Valid Clock Times.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
impl Solution {
2+
// Create 4 vars: h1, h2, m1, m2 & initialize 'output' by 1. Then based on every possible combination of whether h1 & h2 are present, multiply the 'output' accordingly. Repeat the same with m1 & m2
3+
pub fn count_time(time: String) -> i32 {
4+
let mut output = 1;
5+
let h1 = time.chars().nth(0).unwrap();
6+
let h2 = time.chars().nth(1).unwrap();
7+
let m1 = time.chars().nth(3).unwrap();
8+
let m2 = time.chars().nth(4).unwrap();
9+
10+
// ??:xx
11+
if h1 == '?' && h2 == '?' {
12+
output *= 24;
13+
// ?3:xx
14+
} else if (h1 == '?' && (h2 as i32 - '0' as i32) < 4) {
15+
output *= 3;
16+
// ?9:xx
17+
} else if h1 == '?' {
18+
output *= 2;
19+
// 1?:xx
20+
} else if ((h1 as i32 - '0' as i32) < 2) && (h2 == '?') {
21+
output *= 10;
22+
// 2?:xx
23+
} else if ((h1 as i32 - '0' as i32) == 2) && (h2 == '?') {
24+
output *= 4;
25+
}
26+
27+
// xx:??
28+
if m1 == '?' && m2 == '?' {
29+
output *= 60;
30+
// xx:?9
31+
} else if m1 == '?' {
32+
output *= 6;
33+
// xx:5?
34+
} else if m2 == '?' {
35+
output *= 10;
36+
}
37+
38+
return output;
39+
}
40+
}

0 commit comments

Comments
 (0)
Please sign in to comment.