package leetcode;

/**
 * https://leetcode.com/problems/next-closest-time/
 */
public class Problem681 {
    public String nextClosestTime(String time) {
        // TODO
        return "";
    }

    public static void main(String[] args) {
        Problem681 prob = new Problem681();
        System.out.println(prob.nextClosestTime("19:34")); // 19:39
        System.out.println(prob.nextClosestTime("23:59")); // 22:22
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashSet;%0Aimport java.util.Set;%0A%0A
 /**%0A * h
@@ -208,83 +208,843 @@
     
-// TODO%0A        return %22%22;%0A    %7D%0A%0A    public static void main(String%5B%5D args
+Set%3CInteger%3E nums = new HashSet%3C%3E();%0A        for (int i = 0; i %3C time.length(); i++) %7B%0A            if (time.charAt(i) %3E= '0' && time.charAt(i) %3C= '9') %7B%0A                nums.add(time.charAt(i) - '0');%0A            %7D%0A        %7D%0A        int min = Integer.MAX_VALUE;%0A        String closestTime = %22%22;%0A        for (int num1 : nums) %7B%0A            if (num1 %3E 2) %7B%0A                continue;%0A            %7D%0A            for (int num2 : nums) %7B%0A                if (num1 == 2 && num2 %3E 4) %7B%0A                    continue;%0A                %7D%0A                for (int num3 : nums) %7B%0A                    if (num3 %3E 5) %7B%0A                        continue;%0A                    %7D%0A                    for (int num4 : nums) %7B%0A                        String anotherTime = %22%22 + num1 + num2 + %22:%22 + num3 + num4;%0A                        if (time.equals(anotherTime)
 ) %7B%0A
@@ -1055,179 +1055,1011 @@
     
+   
-Problem681 prob = new Problem681();%0A        System.out.println(prob.nextClosestTime(%2219:34%22)); // 19:39%0A        System.out.println(prob.nextClosestTime(%2223:59%22)); // 22:22
+                 continue;%0A                        %7D%0A                        int diff = diff(time, anotherTime);%0A                        if (diff %3C min) %7B%0A                            min = diff;%0A                            closestTime = anotherTime;%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return closestTime.isEmpty() ? time : closestTime;%0A    %7D%0A%0A    private static int diff(String from, String to) %7B%0A        String%5B%5D fromTime = from.split(%22:%22);%0A        int fromHour = Integer.parseInt(fromTime%5B0%5D);%0A        int fromMinute = Integer.parseInt(fromTime%5B1%5D);%0A        String%5B%5D toTime = to.split(%22:%22);%0A        int toHour = Integer.parseInt(toTime%5B0%5D);%0A        int toMinute = Integer.parseInt(toTime%5B1%5D);%0A        int fromMinutes = (fromHour * 60) + fromMinute;%0A        int toMinutes = (toHour * 60) + toMinute;%0A        if (toMinutes %3C fromMinutes) %7B // next day%0A            toMinutes += (24 * 60);%0A        %7D%0A        return toMinutes - fromMinutes;
 %0A   

Solve problem 681