Ad
  • Custom User Avatar

    Hi! Yea, you right. This approach is for more general case and was used hastily.
    Thanks for your attention.

  • Default User Avatar

    Check the fork ;)

  • Default User Avatar

    Is there a reason you did s.length() - s.replace("1", "").length() instead of just replacing all the 0's with "" and returning the length of that? Seems like that would save on a calculation by not having to subtract and you're already doing the replace anyway. Can do it without having to store the string as well that way.