Running Time and Complexity Hacker Rank Solution
class Calculator implements AdvancedArithmetic {
public int divisorSum(int n) {
int sum = 1;
if(n == 1){
return sum;
}
else{
for(int i = 2; i < n; i++){
if(n%i == 0){
sum = sum+i;
}
}
}
return sum+n;
}
}
public int divisorSum(int n) {
int sum = 1;
if(n == 1){
return sum;
}
else{
for(int i = 2; i < n; i++){
if(n%i == 0){
sum = sum+i;
}
}
}
return sum+n;
}
}
Comments
Post a Comment