We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The code can be improved from O(n) to O(n/2) time complexity.
intdivisorSum(intnum){intresult=num;/*Loop only till num/2 elements. You do not have any divisor of num after num/2*/for(inti=1;i<=num/2;i++){if(num%i==0)result+=i;}returnresult;}
Java Interface
You are viewing a single comment's thread. Return to all comments →
The code can be improved from O(n) to O(n/2) time complexity.