Created
January 8, 2019 03:31
-
-
Save ttsugriy/81bd95b2781a57065580789fba4f80a2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| impl Solution { | |
| pub fn find_min_difference(time_points: Vec<String>) -> i32 { | |
| fn to_minutes(time: &str) -> i32 { | |
| let parts: Vec<_> = time.split(":").collect(); | |
| let hours: i32 = parts[0].parse().unwrap(); | |
| let minutes: i32 = parts[1].parse().unwrap(); | |
| hours * 60 + minutes | |
| } | |
| let mut minutes: Vec<_> = time_points.iter().map(|t| to_minutes(&t)).collect(); | |
| minutes.sort_unstable(); | |
| std::cmp::min( | |
| minutes.iter().zip(minutes.iter().skip(1)).map(|(x, y)| y - x).min().unwrap(), | |
| minutes[0] + 1440 - minutes.last().unwrap(), | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment