Leetcode 401 Solution
This article provides solution to leetcode question 401 (binary-watch)
Access this page by simply typing in "lcs 401" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/binary-watch
Solution
class Solution {
public:
vector<string> readBinaryWatch(int num) {
vector<string> res;
for (int h = 0; h < 12; h++)
{
for (int m = 0; m < 60; m++)
{
if (bitset<10>((h << 6) + m).count() == num)
{
res.push_back(to_string(h) + ":" + (m < 10 ? "0" + to_string(m) : to_string(m)));
}
}
}
return res;
}
};