Skip to content

Latest commit

 

History

History
23 lines (23 loc) · 570 Bytes

singlex14.md

File metadata and controls

23 lines (23 loc) · 570 Bytes

Binary Watch

问题分析:

二进制表,利用bitset类,将任意进制数转为二进制,用count函数来统计1的个数

编程实现:

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));
                }
            }
        }
        return res;
    }
};