LeetCode: Latest Time By Replacing Hidden Digits Solution
1var maximumTime = function (time) {2 const fillHour = hh => {3 let [t1, t2] = hh.split("")45 if (t1 === "?" && t2 === "?") {6 t1 = "2"7 t2 = "3"8 }910 if (t1 === "?") {11 if (Number(t2) > 3) {12 t1 = "1"13 } else {14 t1 = "2"15 }16 }1718 if (t2 === "?") {19 if (Number(t1) <= 1) {20 t2 = "9"21 } else {22 t2 = "3"23 }24 }2526 return t1 + t227 }28 const fillMin = mm => {29 let [t1, t2] = mm.split("")3031 if (t1 === "?") {32 t1 = "5"33 }3435 if (t2 === "?") {36 t2 = "9"37 }3839 return t1 + t240 }41 const [hh, mm] = time.split(":")42 return fillHour(hh) + ":" + fillMin(mm)43}
Comments
Loading comments...
Tags
leetcode
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.
Next Post
LeetCode: Minimum Number Of People To Teach
Jan 24, 2021
Previous Post
LeetCode: Find Kth Largest Xor Coordinate Value
Jan 24, 2021