Ad
  • Custom User Avatar

    I disagree. Using a system function to cast the number to string, when bit operations can be used to determine if a bit is set (which is the whole purpose of these operators), is using a rocket launcher to me. The count operation additionally has to view every element.

    Bitwise checks are mostly done, where performance has to be considered. This is why I disagree on this solution being best practice for this particular task.

    Besides, if you'd found this line of code, without the method name, most folks would still not recognize that it counts bits.

    Don't get me entirely wrong, I still think this solution is creative, since is solves the task with minimal effort. I just can't agree on this being best practice.

  • Custom User Avatar

    I'm not sure why so many think this is elegant and considered to be a best practice.
    You should not shoot with rocket launchers at birds.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution