• Skip to primary navigation
  • Skip to content
  • Skip to footer
zhicheng xie's demo blog
  • Quick-Start Guide

    Your Name

    I am an amazing person.

    • Somewhere

    Sort Integers by The Number of 1 Bits

    less than 1 minute read

    <-E 1356> Sort Integers by The Number of 1 Bits

    class Solution {
    public:
      static bool cmp(int a,int b)
        {
            bitset<32> c1(a);
            bitset<32> c2(b);
            int p,q;
            p=c1.count();
            q=c2.count();
            if(p==q)
                return a<b;
            else return p<q;
        }
        vector<int> sortByBits(vector<int>& v) {
            sort(v.begin(),v.end(),cmp);
            return v;
            
        }
    };
    

    Tags: Algorithms, C++, Leetcode

    Updated: July 24, 2020

    Share on

    Twitter Facebook LinkedIn
    Previous Next

    You may also enjoy

    Decode Ways

    less than 1 minute read

    <-M 91> Decode Ways

    Word Break

    less than 1 minute read

    <-H 139> Word Break

    Distinct Subsequences

    less than 1 minute read

    <-H 115> Distinct Subsequences

    Edit Distance

    less than 1 minute read

    <-H 72> Edit Distance

    • Follow:
    • Feed
    © 2023 zhicheng xie's blog. Powered by Jekyll & Minimal Mistakes.