Skip to content

Commit 4e2cada

Browse files
authored
Create largest-time-for-given-digits.py
1 parent 55088a3 commit 4e2cada

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Time: O(1)
2+
# Space: O(1)
3+
4+
import itertools
5+
6+
7+
class Solution(object):
8+
def largestTimeFromDigits(self, A):
9+
"""
10+
:type A: List[int]
11+
:rtype: str
12+
"""
13+
result = ""
14+
for i in xrange(len(A)):
15+
A[i] *= -1
16+
A.sort()
17+
for h1, h2, m1, m2 in itertools.permutations(A):
18+
hours = -(10*h1 + h2)
19+
mins = -(10*m1 + m2)
20+
if 0 <= hours < 24 and 0 <= mins < 60:
21+
result = "{:02}:{:02}".format(hours, mins)
22+
break
23+
return result
24+

0 commit comments

Comments
 (0)