This Problem is Trivial in Java


  • -4
    C

    Integer.bitCount(n);

    This will do the work.


  • 2
    L

    or you can do stuff like

    if(n==1 || n==2 || n==4 || n== 8 || ...)
        return 1;
    if(n==3 || n==5 || n==6)
        return 2;
    if(n==7 ||...)
        return 3;
    ...
    

    but the point is to come up with the algorithm!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.