Skip to content

Commit

Permalink
Create latest-time-by-replacing-hidden-digits.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Jan 25, 2021
1 parent 096ec02 commit f3afe42
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions C++/latest-time-by-replacing-hidden-digits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Time: O(1)
// Space: O(1)

class Solution {
public:
string maximumTime(string time) {
for (int i = 0; i < size(time); ++i) {
if (time[i] != '?') {
continue;
}
if (i == 0) {
time[i] = (time[1] <= '3' || time[1] == '?') ? '2' : '1';
} else if (i == 1) {
time[i] = (time[0] == '2') ? '3' : '9';
} else if (i == 3) {
time[i] = '5';
} else if (i == 4) {
time[i] = '9';
}
}
return time;
}
};

0 comments on commit f3afe42

Please sign in to comment.