Ad
  • Custom User Avatar

    这么写也太赖皮了

  • Default User Avatar

    i believe performance is always the main concern; it isnt about looking cool and getting it in one line; that is clever yes but not best practice; best practice means most efficient and clear and scalable (which means if you want to add or remove a aspect of the code you dont have to rework on all aspects of the code only the aspect you want to) ALWAYS!!!!

  • Custom User Avatar

    why isn't it necessary to cast to int?

  • Custom User Avatar

    What qualifies as "best practice" depends on the context. When performance is a concern, yes, an O(n) solution is best practice. When performance is not a concern, clarity and maintainability is best practice. Performance is generally not a concern when the potential number of items results in little or no discernable delay in processing. To be fair, though, I find this solution to be neither fastest nor clearest. I think what the author was going for was "most succinct."

  • Custom User Avatar

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