Skip to content

Commit 5fcb181

Browse files
authored
Create 1736-latest-time-by-replacing-hidden-digits.js
1 parent 5d59996 commit 5fcb181

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @param {string} time
3+
* @return {string}
4+
*/
5+
var maximumTime = function(time) {
6+
const arr = time.split('')
7+
let idx = time.indexOf('?')
8+
if(idx < 0) return time
9+
while(arr.indexOf('?') >= 0) {
10+
idx = arr.indexOf('?')
11+
let e
12+
if(idx === 0) {
13+
if(time[1] === '?') e = 2
14+
else if(+time[1] < 4) e =2
15+
else e = 1
16+
arr[0] = '' + e
17+
18+
} else if(idx === 1) {
19+
if(+arr[0] > 1) e = 3
20+
else e = 9
21+
arr[1] = '' + e
22+
} else if(idx === 3) {
23+
e = 5
24+
arr[3] = '' + e
25+
} else if(idx === 4) {
26+
e = 9
27+
arr[4] = '' + e
28+
}
29+
}
30+
31+
return arr.join('')
32+
};

0 commit comments

Comments
 (0)