leetCode401

mac2024-07-12  47

认识了bitset

class Solution { public: vector<string> readBinaryWatch(int num) { vector<string>ans; for(int i = 0;i<12;i++) { bitset<4>h(i); for(int j = 0;j<60;j++) { bitset<6>m(j); if(h.count() + m.count() == num) { ans.push_back(to_string(i) + ":" + (j<10 ? "0" + to_string(j) : to_string(j))); } } } return ans; } };

 

最新回复(0)