Ad
  • Custom User Avatar

    I didn't know that cause that's not what you said in your comment. That's still slower for large number sizes, e.g 32 bit integers (the most common size for an integer in cpp), although if we're being specific since we're dealing with signed integers here, so the max would be like 2^31 - 1. I agree that for small numbers, the iterative method is faster, but not by much as both methods are practically instant when dealing with small numbers. It's better to make the function scalable to larger numbers by using this method.

  • Custom User Avatar

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