Ad
  • Custom User Avatar

    This one has constant comlexity O(1), while an iterator will have at least linear complexity O(n).
    While this doesn't make this automatically more efficient for small values, we can optimise this solution by using bit operation for deviding but the compiler already does that for us.
    So that means this solutuon needs 4 arthmic operations to execute, while the iterator solution needs at least n arethmic operations, meaning that if n is bigger than 4 the iterator solution is already worse.