Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_seconds(time):
- hours = int(time[:2])
- minutes = int(time[3:5])
- seconds = int(time[6:])
- return 3600 * hours + 60 * minutes + seconds
- def is_in_range(time, min_time, max_time):
- time_seconds = get_seconds(time)
- min_time_seconds = get_seconds(min_time)
- max_time_seconds = get_seconds(max_time)
- return min_time_seconds <= time_seconds <= max_time_seconds
- def generate_times_for_hour(hour):
- if len(set(hour)) == 2:
- return set([hour + ':' + m1 + s1 + ':' + m2 + s2 for m1 in hour for s1 in hour for m2 in hour for s2 in hour])
- else:
- letter = hour[0]
- letters = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
- combinations = [letter + x for x in letters]
- result = set()
- for xs in combinations:
- result = result.union(set([hour + ':' + m1 + s1 + ':' + m2 + s2 for m1 in xs for s1 in xs for m2 in xs for s2 in xs]))
- return result
- def solution(S, T):
- startHour = int(S[:2])
- endHour = int(T[:2])
- result = 0
- for h in range(startHour, endHour+1):
- result += len([time for time in generate_times_for_hour(str(h)) if is_in_range(time, S, T)])
- return result
- # print(solution("11:12:43", "16:13:10"))
- print(solution("22:22:21", "22:22:23"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement