public class Solution {
public List<String > readBinaryWatch(int num) {
List<String > list = new ArrayList<>();
if (num==0 ) {
list.add("0:00" );
return list;
}
int [] hours = {1 ,2 ,4 ,8 };
int [] minutes = {1 ,2 ,4 ,8 ,16 ,32 };
for (int i =0 ;i <= num;i++) {
String hour = "" ;
List<Integer> hourList = new ArrayList<>();
List<Integer> minuList = new ArrayList<>();
if (i == 0 ) {
hourList.add(0 );
}else {
combine(hours,i,0 ,0 ,hourList,0 ,12 );
}
if (num-i == 0 ) {
minuList.add(0 );
}else {
combine(minutes,num-i,0 ,0 ,minuList,0 ,60 );
}
for (Integer h : hourList) {
for (Integer m : minuList) {
list.add(h+":" + String .format("%02d" ,m));
}
}
}
return list;
}
public void combine(int [] hour ,int count,int len ,int pos, List<Integer> list, int cur, int limit) {
if (len >count) {
return;
}else if (len == count) {
if (cur<limit) {
list.add(cur);
}
}else if (cur>=limit) {
return;
}else {
for (int j =pos;j< hour .length;j++) {
cur +=hour [j];
combine(hour ,count,len +1 ,j+1 ,list,cur,limit);
cur-=hour [j];
}
}
}
}