public class Solution {
public List<String> readBinaryWatch(int num) {
List<String> list = new ArrayList<String>();
if(num==0){
list.add("0:00");
return list;
}
int[] hlist = {1,2,4,8};
int[] minlist = {1,2,4,8,16,32};
for(int i=0;i<=4;i++){
if(num-i>6) continue;
List<Integer> hours = new ArrayList<Integer>();
List<Integer> mins = new ArrayList<Integer>();
gettime(hlist,i,0, 0, hours);
gettime(minlist,num-i,0, 0, mins);
Collections.sort(hours);
Collections.sort(mins);
for(Integer h : hours)
for(Integer s : mins)
list.add(String.format("%d:%02d", h, s));
}
return list;
}
public void gettime(int[] hlist, int remain, int idx, int cur, List<Integer> list){
if(idx>hlist.length||remain<0) return;
if(remain==0){
list.add(cur);
return;
}
for(int i=idx;i<hlist.length;i++){
gettime(hlist, remain-1, i+1, cur+hlist[i], list);
}
}
}