forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0949.py
More file actions
26 lines (22 loc) · 681 Bytes
/
Copy path0949.py
File metadata and controls
26 lines (22 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from itertools import permutations
class Solution:
def largestTimeFromDigits(self, A):
"""
:type A: List[int]
:rtype: str
"""
A_per = permutations(A)
res = ''
for a in A_per:
pre = a[0]*10 + a[1]
pos = a[2]*10 + a[3]
if pre > 23 or pos > 59:
continue
str_pre, str_pos = str(pre), str(pos)
if a[0] == 0:
str_pre = '0' + str_pre
if a[2] == 0:
str_pos = '0' + str_pos
cur = str_pre + ':' + str_pos
res = max(cur, res)
return res