Last active
July 21, 2018 03:54
-
-
Save waynejo/4355b3296db808f97b096a7261ae20ee 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
func stringAsMinutes(timeString string) int { | |
hour := int(timeString[0] - '0') * 10 + int(timeString[1] - '0') | |
minute := int(timeString[3] - '0') * 10 + int(timeString[4] - '0') | |
return hour * 60 + minute | |
} | |
func findMinDifference(timePoints []string) int { | |
sort.Strings(timePoints) | |
lenOfTimes := len(timePoints) | |
minuteArray := make([]int, 0) | |
for i := 0; i < lenOfTimes; i++ { | |
minuteArray = append(minuteArray, stringAsMinutes(timePoints[i])) | |
} | |
minuteArray = append(minuteArray, stringAsMinutes(timePoints[0]) + 24 * 60) | |
lenOfMinute := len(minuteArray) | |
var minDiff = 24 * 60 | |
for i := 1; i < lenOfMinute; i++ { | |
diff := minuteArray[i] - minuteArray[i - 1] | |
if (minDiff > diff) { | |
minDiff = diff | |
} | |
} | |
return minDiff | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment