Returning large - small is not what is asked for.
You should make the sum of all values, then subtract large from it, then subtract small from it, then divide by the length of the array minus 2.
That's the value to return.
public int centeredAverage(int[] nums) {
int large=0;
int small=0;
for(int n:nums){
large= Math.max(large, n);
//large=n;
}
for(int n:nums){
small= Math.min(large, n);
// small=n;
}
return (large-small);
}
public int centeredAverage(int[] nums) {
int large=Integer.MIN_VALUE;
int small=Integer.MAX_VALUE;
int sum=0;
for(int n:nums){
large = Math.max(large, n);
small = Math.min(small, n);
sum += n;
}
return (sum-large-small)/(nums.length-2);
}
public int centeredAverage(int[] nums) {
int large=Integer.MIN_VALUE;
int small=Integer.MAX_VALUE;
int sum=0;
for(int n:nums){
large = Math.max(large, n);
small = Math.min(small, n);
sum += n;
}
return (sum-large-small)/(nums.length-2);
}
public int centeredAverage(int[] nums) {
int large=0;
int small=0;
for(int n:nums){
large= Math.max(large, n);
//large=n;
}
for(int n:nums){
small= Math.min(large, n);
// small=n;
}
return (large-small);
}
Which is absolutely not similar.Title | # Comments | Views | Activity |
---|---|---|---|
how to use external config file with Spring MVC | 4 | 58 | |
Exe program is not a valid Win 32 application | 15 | 95 | |
Change to event | 1 | 72 | |
why my code login on a web site with access vba don't work on microsoft access 2016 | 26 | 43 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
7 Experts available now in Live!