Leetcode 986 Solution
This article provides solution to leetcode question 986 (largest-time-for-given-digits)
Access this page by simply typing in "lcs 986" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/largest-time-for-given-digits
Solution
class Solution:
def largestTimeFromDigits(self, A: List[int]) -> str:
ans = ""
for h1, h2, m1, m2 in itertools.permutations(A):
h = h1 * 10 + h2
m = m1 * 10 + m2
if h < 24 and m < 60:
ans = max(ans, "{}{}:{}{}".format(h1, h2, m1, m2))
return ans