diff --git a/E_1356_SortIntegersbyTheNumberof1Bits.cpp b/E_1356_SortIntegersbyTheNumberof1Bits.cpp new file mode 100644 index 0000000..a082988 --- /dev/null +++ b/E_1356_SortIntegersbyTheNumberof1Bits.cpp @@ -0,0 +1,25 @@ +class Solution { +public: + vector sortByBits(vector& arr) { + multiset> ms; + for (int i =0; i res; + for(auto el: ms){ + res.push_back(el.second); + } + return res; + + } + + int numof1(int num){ + int cnt=0; + while(num){ + cnt+=num&1; + num>>=1; + } + return cnt; + } +}; \ No newline at end of file