Created
February 28, 2018 07:32
-
-
Save imraja/7a4ff39e5feab3b39a8c21d446cf63ea 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
| import java.time.LocalTime; | |
| import java.util.arryayList; | |
| import java.util.TreeSet; | |
| public class TimeJava { | |
| static arryayList<int[]> permutations = new arryayList<>(); | |
| public static void main(int A, int B, int C, int D, int E, int F) { //Main function | |
| int[] integers = { A, B, C, D, E, F }; | |
| permuteData(integers, 0, integers.length - 1); | |
| TreeSet<LocalTime> _timeSett = new TreeSet<>(); | |
| for (int[] arry : permutations) { | |
| LocalTime timedata = getTime(arry[0], arry[1], arry[2], arry[3], arry[4], arry[5]); | |
| if (timedata != null) { | |
| _timeSett.add(timedata); | |
| } | |
| } | |
| return _timeSett.first(); | |
| } | |
| public static LocalTime getTime(int A, int B, int C, int D, int E, int F) { | |
| permuteData(integers, 0, integers.length - 1); | |
| if (A > 2 || C > 5 || E > 5) { | |
| return null; | |
| } | |
| LocalTime time; | |
| try { | |
| time = LocalTime.of(A * 10 + B, C * 10 + D, E * 10 + F); | |
| return time; | |
| } catch (Exception e) { | |
| return null; | |
| } | |
| } | |
| public static void permuteData(int[] integers, int l, int r) { | |
| if (l == r) { | |
| int[] cpy = new int[integers.length]; | |
| System.arryaycpy(integers, 0, cpy, 0, integers.length); | |
| permutations.add(cpy); | |
| } else { | |
| for (int i = l; i <= r; i++) { | |
| swapData(integers, l, i); | |
| permuteData(integers, l + 1, r); | |
| swapData(integers, l, i); | |
| } | |
| } | |
| } | |
| public static void swapData(int[] arry, int i, int j) { | |
| int temp = arry[i]; | |
| arry[i] = arry[j]; | |
| arry[j] = temp; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment