Skip to content

Commit f3afe42

Browse files
authored
Create latest-time-by-replacing-hidden-digits.cpp
1 parent 096ec02 commit f3afe42

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Time: O(1)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
string maximumTime(string time) {
7+
for (int i = 0; i < size(time); ++i) {
8+
if (time[i] != '?') {
9+
continue;
10+
}
11+
if (i == 0) {
12+
time[i] = (time[1] <= '3' || time[1] == '?') ? '2' : '1';
13+
} else if (i == 1) {
14+
time[i] = (time[0] == '2') ? '3' : '9';
15+
} else if (i == 3) {
16+
time[i] = '5';
17+
} else if (i == 4) {
18+
time[i] = '9';
19+
}
20+
}
21+
return time;
22+
}
23+
};

0 commit comments

Comments
 (0)