401. Binary Watch
Input: n = 1
Return: ["1:00", "2:00", "4:00", "8:00", "0:01", "0:02", "0:04", "0:08", "0:16", "0:32"]public class Solution {
public IList<string> ReadBinaryWatch(int num) {
var output = new List<string>();
for(int h = 0; h <= 11; h++){
for(int m = 0 ; m <= 59; m++){
char[] charlist = (Convert.ToString(h,2) + Convert.ToString(m,2)).ToCharArray();
var count = charlist.Count(c => c == '1');
if(count == num){
output.Add(string.Format("{0}:{1:00}", h, m));
}
}
}
return output;
}
}Last updated
