From b176ab2acbb768a867ad48c65735b12ee920cd60 Mon Sep 17 00:00:00 2001 From: isinsuarici Date: Sun, 11 Dec 2022 08:28:56 +0300 Subject: [PATCH] 1356 --- E_1356_SortIntegersbyTheNumberof1Bits.cpp | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 E_1356_SortIntegersbyTheNumberof1Bits.cpp 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