You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/3100-3199/3114.Latest Time You Can Obtain After Replacing Characters/README_EN.md
+118
Original file line number
Diff line number
Diff line change
@@ -153,4 +153,122 @@ function findLatestTime(s: string): string {
153
153
154
154
<!-- tabs:end -->
155
155
156
+
### Solution 2: Judge Each Digit
157
+
158
+
We can judge each digit of $s$ one by one. If it is "?", we determine the value of this digit based on the characters before and after it. Specifically, we have the following rules:
159
+
160
+
- If $s[0]$ is "?", then the value of $s[0]$ should be "1" or "0", depending on the value of $s[1]$. If $s[1]$ is "?" or $s[1]$ is less than "2", then the value of $s[0]$ should be "1", otherwise the value of $s[0]$ should be "0".
161
+
- If $s[1]$ is "?", then the value of $s[1]$ should be "1" or "9", depending on the value of $s[0]$. If $s[0]$ is "1", then the value of $s[1]$ should be "1", otherwise the value of $s[1]$ should be "9".
162
+
- If $s[3]$ is "?", then the value of $s[3]$ should be "5".
163
+
- If $s[4]$ is "?", then the value of $s[4]$ should be "9".
164
+
165
+
The time complexity is $O(1)$, and the space complexity is $O(1)$.
0 commit comments