Created
May 22, 2021 01:00
-
-
Save KingAshiru/05595ad358daca584f3c96207bf9757c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def findMinDiff(self, times): | |
if len(times) < 1: | |
return 0 | |
timelist = [] | |
# convert all times to minutes | |
for time in times: | |
minutes = int(time[0:2]) * 60 + int(time[3:5]) | |
minutes2 = minutes + (24 * 60) # we need to cover for times closer to midnight (00:00) | |
timelist.append(minutes2) | |
timelist.append(minutes) | |
timelist.sort() | |
diff = (24 * 60) + 1 # set a dummy to estimate minimum | |
for i in range(len(timelist) - 1): | |
diff = min(diff, timelist[i+1] - timelist[i]) | |
return diff | |
# Time O(NlogN) | |
# Space O(N) |
Hello @KingAshiru, congratulations 🎉 your solution has been selected as one of the winning solutions in Week 7 of #AlgorithmFridays.
Your solution is clean and readable and really neat.
Out of the many winning solutions, only 3 will be selected for the 20$ prize in a raffle draw. The raffle draw will hold today, Friday May 28 at 3.00pm WAT (7.00 am PST)
If you are interested in being a part of the raffle draw, please send me a DM on Twitter @meekg33k so I can share the event invite with you.
NB: Only solutions of participants who indicated interest in the raffle draw will be considered.
Thanks once again for participating and see you later today for Week 8 of #AlgorithmFridays.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
neat code