-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindShortestTime.java
More file actions
36 lines (29 loc) · 879 Bytes
/
findShortestTime.java
File metadata and controls
36 lines (29 loc) · 879 Bytes
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
import java.util.Scanner;
public class findShortestTime {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = Integer.parseInt(in.nextLine());
String[] time = new String[n];
for(int i=0; i<n; i++) {
time[i] = in.nextLine();
}
//Output
System.out.println(findShortestTime(time));
}
public static String findShortestTime(String[] time) {
int minVal = Integer.MAX_VALUE;
String min = null;
for(int i=0; i<time.length; i++) {
String duration = time[i];
int hours = Integer.parseInt(duration.split(":")[0]);
int mins = Integer.parseInt(duration.split(":")[1]);
int secs = Integer.parseInt(duration.split(":")[2]);
int totalSecs = hours*3600 + mins*60 + secs;
if(totalSecs < minVal) {
minVal = totalSecs;
min = duration;
}
}
return min;
}
}