-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathgreatest-time.py
49 lines (35 loc) · 1011 Bytes
/
greatest-time.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'''Find the greatest military time that can be created from four digits.'''
def greatestTime(A, B, C, D):
tmp = [A, B, C, D]
hour0 = None
for i in tmp:
if i <= 2 and (hour0 is None or i > hour0):
hour0 = i
if hour0 is None:
return "NO VALID TIME"
tmp.remove(hour0)
hour1 = None
for i in tmp:
if hour0 == 2:
if i <= 4 and (hour1 is None or i > hour1):
hour1 = i
else:
if hour1 is None or i > hour1:
hour1 = i
if hour1 is None:
return "NO VALID TIME"
tmp.remove(hour1)
min0 = None
for i in tmp:
if i <= 5 and (min0 is None or i > min0):
min0 = i
if min0 is None:
return "NO VALID TIME"
tmp.remove(min0)
min1 = None
for i in tmp:
if min1 is None or i > min1:
min1 = i
if min1 is None:
return "NO VALID TIME"
return str(hour0) + str(hour1) + ":" + str(min0) + str(min1)