You are viewing a single comment's thread. Return to all comments →
My java solution with O(sqrt(n)) complexity -
public int divisorSum(int n) { int sum = n+1; for(int i=2;i<=Math.sqrt(n);i++) { if(n%i==0){ sum = sum+i; if((n/i)!=i){ sum=sum+(n/i); } } } return n==1?1:sum; }
Day 19: Interfaces
You are viewing a single comment's thread. Return to all comments →
My java solution with O(sqrt(n)) complexity -