yeah I was thinking of changing least significant digit one by one solution but since there's only 4 * 4 * 4 * 4 possible outcome brute force makes sense to me.

here is mine:

public String nextClosestTime(String time) {
int[] digits = {time.charAt(0) - '0', time.charAt(1) - '0', time.charAt(3) - '0', time.charAt(4) - '0'};
int min = Integer.MAX_VALUE;
int timeInMin = timeInMin(digits[0], digits[1], digits[2], digits[3]);
String ret = "";
for (int i : digits)
for (int j : digits)
for (int k : digits)
for (int l : digits)
if ((i*10 + j) >= 0 && (i*10 + j) < 24 && (k * 10 + l) >= 0 && (k * 10 + l) < 60){//(i, j, k, l) forms valid time
int temp = timeInMin(i, j, k, l);
if (temp <= timeInMin)
temp += 24*60;//going 1 day forward
if (temp - timeInMin < min){
min = temp - timeInMin;
ret = "" + i + j + ":" + k + l;
}
}
return ret;
}
private int timeInMin(int d0, int d1, int d2, int d3){
return (d0*10 + d1)*60 + (d2*10 + d3);
}