Skip to content

Commit eadb147

Browse files
committed
New Problem Solution -"Latest Time by Replacing Hidden Digits"
1 parent 667ba8c commit eadb147

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ LeetCode
4949
|1750|[Minimum Length of String After Deleting Similar Ends](https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends/) | [C++](./algorithms/cpp/minimumLengthOfStringAfterDeletingSimilarEnds/MinimumLengthOfStringAfterDeletingSimilarEnds.cpp)|Medium|
5050
|1749|[Maximum Absolute Sum of Any Subarray](https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray/) | [C++](./algorithms/cpp/maximumAbsoluteSumOfAnySubarray/MaximumAbsoluteSumOfAnySubarray.cpp)|Medium|
5151
|1748|[Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements/) | [C++](./algorithms/cpp/sumOfUniqueElements/SumOfUniqueElements.cpp)|Easy|
52+
|1736|[Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits/) | [C++](./algorithms/cpp/latestTimeByReplacingHiddenDigits/LatestTimeByReplacingHiddenDigits.cpp)|Easy|
5253
|1734|[Decode XORed Permutation](https://leetcode.com/problems/decode-xored-permutation/) | [C++](./algorithms/cpp/decodeXORedPermutation/DecodeXoredPermutation.cpp)|Medium|
5354
|1733|[Minimum Number of People to Teach](https://leetcode.com/problems/minimum-number-of-people-to-teach/) | [C++](./algorithms/cpp/minimumNumberOfPeopleToTeach/MinimumNumberOfPeopleToTeach.cpp)|Medium|
5455
|1732|[Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude/) | [C++](./algorithms/cpp/findTheHighestAltitude/FindTheHighestAltitude.cpp)|Easy|
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Source : https://leetcode.com/problems/latest-time-by-replacing-hidden-digits/
2+
// Author : Hao Chen
3+
// Date : 2021-03-27
4+
5+
/*****************************************************************************************************
6+
*
7+
* You are given a string time in the form of hh:mm, where some of the digits in the string are
8+
* hidden (represented by ?).
9+
*
10+
* The valid times are those inclusively between 00:00 and 23:59.
11+
*
12+
* Return the latest valid time you can get from time by replacing the hidden digits.
13+
*
14+
* Example 1:
15+
*
16+
* Input: time = "2?:?0"
17+
* Output: "23:50"
18+
* Explanation: The latest hour beginning with the digit '2' is 23 and the latest minute ending with
19+
* the digit '0' is 50.
20+
*
21+
* Example 2:
22+
*
23+
* Input: time = "0?:3?"
24+
* Output: "09:39"
25+
*
26+
* Example 3:
27+
*
28+
* Input: time = "1?:22"
29+
* Output: "19:22"
30+
*
31+
* Constraints:
32+
*
33+
* time is in the format hh:mm.
34+
* It is guaranteed that you can produce a valid time from the given string.
35+
******************************************************************************************************/
36+
37+
class Solution {
38+
public:
39+
string maximumTime(string time) {
40+
41+
if (time[0] == '?' ) {
42+
time[0] = (time[1] == '?' || time[1] < '4') ? '2' : '1';
43+
}
44+
if (time[1] == '?' ) {
45+
time[1] = ( time[0] == '2' ) ? '3' : '9';
46+
}
47+
if (time[3] == '?') time[3] = '5';
48+
if (time[4] == '?') time[4] = '9';
49+
return time;
50+
}
51+
};

0 commit comments

Comments
 (0)