My leetcode submissions.
at main 336 B view raw
1#include <vector> 2#include <iostream> 3#include <bitset> 4using namespace std; 5 6auto countBits(int n) -> vector<int> 7{ 8 auto x = 0; 9 auto a = vector<int>(n + 1, 0); 10 for (auto x = 0; auto& k : a) 11 k = bitset<32>(x++).count(); 12 13 return a; 14} 15 16auto main() -> int 17{ 18 for (auto const& n : countBits(5)) 19 std::cout << n << ' '; 20 return 0; 21} 22