Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ee32cb5

Browse files
committed
feat: add solutions to lc problem: No.1736. Latest Time by Replacing
Hidden Digits
1 parent 31c18df commit ee32cb5

File tree

6 files changed

+234
-2
lines changed

6 files changed

+234
-2
lines changed

‎solution/1700-1799/1736.Latest Time by Replacing Hidden Digits/README.md‎

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,95 @@
5757
<!-- 这里可写当前语言的特殊实现逻辑 -->
5858

5959
```python
60-
60+
class Solution:
61+
def maximumTime(self, time: str) -> str:
62+
t = list(time)
63+
if t[0] == '?':
64+
t[0] = '1' if '4' <= t[1] <= '9' else '2'
65+
if t[1] == '?':
66+
t[1] = '3' if t[0] == '2' else '9'
67+
if t[3] == '?':
68+
t[3] = '5'
69+
if t[4] == '?':
70+
t[4] = '9'
71+
return ''.join(t)
6172
```
6273

6374
### **Java**
6475

6576
<!-- 这里可写当前语言的特殊实现逻辑 -->
6677

6778
```java
79+
class Solution {
80+
public String maximumTime(String time) {
81+
char[] t = time.toCharArray();
82+
if (t[0] == '?') {
83+
t[0] = t[1] >= '4' && t[1] <= '9' ? '1' : '2';
84+
}
85+
if (t[1] == '?') {
86+
t[1] = t[0] == '2' ? '3' : '9';
87+
}
88+
if (t[3] == '?') {
89+
t[3] = '5';
90+
}
91+
if (t[4] == '?') {
92+
t[4] = '9';
93+
}
94+
return new String(t);
95+
}
96+
}
97+
```
98+
99+
### **C++**
100+
101+
```cpp
102+
class Solution {
103+
public:
104+
string maximumTime(string time) {
105+
if (time[0] == '?') {
106+
time[0] = (time[1] >= '4' && time[1] <= '9') ? '1' : '2';
107+
}
108+
if (time[1] == '?') {
109+
time[1] = (time[0] == '2') ? '3' : '9';
110+
}
111+
if (time[3] == '?') {
112+
time[3] = '5';
113+
}
114+
if (time[4] == '?') {
115+
time[4] = '9';
116+
}
117+
return time;
118+
}
119+
};
120+
```
68121
122+
### **Go**
123+
124+
```go
125+
func maximumTime(time string) string {
126+
t := []byte(time)
127+
if t[0] == '?' {
128+
if t[1] >= '4' && t[1] <= '9' {
129+
t[0] = '1'
130+
} else {
131+
t[0] = '2'
132+
}
133+
}
134+
if t[1] == '?' {
135+
if t[0] == '2' {
136+
t[1] = '3'
137+
} else {
138+
t[1] = '9'
139+
}
140+
}
141+
if t[3] == '?' {
142+
t[3] = '5'
143+
}
144+
if t[4] == '?' {
145+
t[4] = '9'
146+
}
147+
return string(t)
148+
}
69149
```
70150

71151
### **...**

‎solution/1700-1799/1736.Latest Time by Replacing Hidden Digits/README_EN.md‎

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,93 @@
4949
### **Python3**
5050

5151
```python
52-
52+
class Solution:
53+
def maximumTime(self, time: str) -> str:
54+
t = list(time)
55+
if t[0] == '?':
56+
t[0] = '1' if '4' <= t[1] <= '9' else '2'
57+
if t[1] == '?':
58+
t[1] = '3' if t[0] == '2' else '9'
59+
if t[3] == '?':
60+
t[3] = '5'
61+
if t[4] == '?':
62+
t[4] = '9'
63+
return ''.join(t)
5364
```
5465

5566
### **Java**
5667

5768
```java
69+
class Solution {
70+
public String maximumTime(String time) {
71+
char[] t = time.toCharArray();
72+
if (t[0] == '?') {
73+
t[0] = t[1] >= '4' && t[1] <= '9' ? '1' : '2';
74+
}
75+
if (t[1] == '?') {
76+
t[1] = t[0] == '2' ? '3' : '9';
77+
}
78+
if (t[3] == '?') {
79+
t[3] = '5';
80+
}
81+
if (t[4] == '?') {
82+
t[4] = '9';
83+
}
84+
return new String(t);
85+
}
86+
}
87+
```
88+
89+
### **C++**
90+
91+
```cpp
92+
class Solution {
93+
public:
94+
string maximumTime(string time) {
95+
if (time[0] == '?') {
96+
time[0] = (time[1] >= '4' && time[1] <= '9') ? '1' : '2';
97+
}
98+
if (time[1] == '?') {
99+
time[1] = (time[0] == '2') ? '3' : '9';
100+
}
101+
if (time[3] == '?') {
102+
time[3] = '5';
103+
}
104+
if (time[4] == '?') {
105+
time[4] = '9';
106+
}
107+
return time;
108+
}
109+
};
110+
```
58111
112+
### **Go**
113+
114+
```go
115+
func maximumTime(time string) string {
116+
t := []byte(time)
117+
if t[0] == '?' {
118+
if t[1] >= '4' && t[1] <= '9' {
119+
t[0] = '1'
120+
} else {
121+
t[0] = '2'
122+
}
123+
}
124+
if t[1] == '?' {
125+
if t[0] == '2' {
126+
t[1] = '3'
127+
} else {
128+
t[1] = '9'
129+
}
130+
}
131+
if t[3] == '?' {
132+
t[3] = '5'
133+
}
134+
if t[4] == '?' {
135+
t[4] = '9'
136+
}
137+
return string(t)
138+
}
59139
```
60140

61141
### **...**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
string maximumTime(string time) {
4+
if (time[0] == '?') {
5+
time[0] = (time[1] >= '4' && time[1] <= '9') ? '1' : '2';
6+
}
7+
if (time[1] == '?') {
8+
time[1] = (time[0] == '2') ? '3' : '9';
9+
}
10+
if (time[3] == '?') {
11+
time[3] = '5';
12+
}
13+
if (time[4] == '?') {
14+
time[4] = '9';
15+
}
16+
return time;
17+
}
18+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
func maximumTime(time string) string {
2+
t := []byte(time)
3+
if t[0] == '?' {
4+
if t[1] >= '4' && t[1] <= '9' {
5+
t[0] = '1'
6+
} else {
7+
t[0] = '2'
8+
}
9+
}
10+
if t[1] == '?' {
11+
if t[0] == '2' {
12+
t[1] = '3'
13+
} else {
14+
t[1] = '9'
15+
}
16+
}
17+
if t[3] == '?' {
18+
t[3] = '5'
19+
}
20+
if t[4] == '?' {
21+
t[4] = '9'
22+
}
23+
return string(t)
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public String maximumTime(String time) {
3+
char[] t = time.toCharArray();
4+
if (t[0] == '?') {
5+
t[0] = t[1] >= '4' && t[1] <= '9' ? '1' : '2';
6+
}
7+
if (t[1] == '?') {
8+
t[1] = t[0] == '2' ? '3' : '9';
9+
}
10+
if (t[3] == '?') {
11+
t[3] = '5';
12+
}
13+
if (t[4] == '?') {
14+
t[4] = '9';
15+
}
16+
return new String(t);
17+
}
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def maximumTime(self, time: str) -> str:
3+
t = list(time)
4+
if t[0] == '?':
5+
t[0] = '1' if '4' <= t[1] <= '9' else '2'
6+
if t[1] == '?':
7+
t[1] = '3' if t[0] == '2' else '9'
8+
if t[3] == '?':
9+
t[3] = '5'
10+
if t[4] == '?':
11+
t[4] = '9'
12+
return ''.join(t)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /