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.
Day 19: Interfaces
Day 19: Interfaces
Sort by
recency
|
811 Discussions
|
Please Login in order to post a comment
Python 3 - Code to Optimizing time
`In Java 8 import java.io.; import java.util.;
interface AdvancedArithmetic{ int divisorSum(int n); } class Calculator implements AdvancedArithmetic { public int divisorSum(int n) { int sum=0; for(int i=1;i<=n;i++) { if(n%i==0) { sum+=i; } } return sum; } }
class Solution {
} `
def divisorSum(self, n): divisors = [] for i in range(1,n+1): if n%i==0: divisors.append(i) return sum(divisors)
Python3 :