题目描述
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1535484627ea19a28078dc17af97bc1f.png)
代码
public static List<String> readBinaryWatch(int turnedOn) {
List<String> ans = new ArrayList<String>();
for(int i=0;i<=11;i++) {
for(int j=0;j<=59;j++) {
int count=0;
String temp = Integer.toBinaryString(i);
for(int k=0;k<temp.length();k++) {
if(temp.charAt(k)=='1') count++;
}
temp = Integer.toBinaryString(j);
for(int k=0;k<temp.length();k++) {
if(temp.charAt(k)=='1') count++;
}
if(count==turnedOn) {
String target = String.valueOf(i)+":";
if(j==0) target=target+"00";
else if(j<=9) target = target+"0"+j;
else target = target+j;
ans.add(target);
}
}
}
return ans;
}