Skip to main content

New answers tagged

-1 votes

Optimal Solution for the Four Divisors Problem on LeetCode

Here is an updated version of the code: ...
BrunoBarreto's user avatar
4 votes

Optimal Solution for the Four Divisors Problem on LeetCode

I found it odd (pardon the pun) that your “divisible by 4” check is before your “divisible by 2” check. You only need to check if the number is divisible by 4 if it is divisible by 2, which is ...
AJNeufeld's user avatar
  • 33.6k
5 votes

Optimal Solution for the Four Divisors Problem on LeetCode

nested function Thank you for breaking out a Helper. def sumFourDivisors(... ... def sumFourDivisors_aux(n): I will offer my usual advice: Make ...
J_H's user avatar
  • 25.7k
4 votes

Optimal Solution for the Four Divisors Problem on LeetCode

We could move the test for divisibility by 4 before the more expensive square-root operation. Note also that we have a specific code path for number 8, so we could hard-code a return there: ...
Toby Speight's user avatar
  • 75.2k

Top 50 recent answers are included