Ad
  • 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.