public int bigDiff(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);
}
Expected Run
bigDiff([10, 3, 5, 6]) → 7 4 X
bigDiff([7, 2, 10, 9]) → 8 1 X
bigDiff([2, 10, 7, 2]) → 8 8 OK
bigDiff([2, 10]) → 8 0 X
bigDiff([10, 2]) → 8 8 OK
bigDiff([10, 0]) → 10 10 OK
bigDiff([2, 3]) → 1 0 X
bigDiff([2, 2]) → 0 0 OK
bigDiff([2]) → 0 0 OK
bigDiff([5, 1, 6, 1, 9, 9]) → 8 0 X
bigDiff([7, 6, 8, 5]) → 3 3 OK
bigDiff([7, 7, 6, 8, 5, 5, 6]) → 3 2 X
other tests
X
I know that; I'm trying to get him closer to the solution, without giving it to him.
public int bigDiff(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(small, n);
// small=n;
}
return (large-small);
}
Expected Run
bigDiff([10, 3, 5, 6]) → 7 10 X
bigDiff([7, 2, 10, 9]) → 8 10 X
bigDiff([2, 10, 7, 2]) → 8 10 X
bigDiff([2, 10]) → 8 10 X
bigDiff([10, 2]) → 8 10 X
bigDiff([10, 0]) → 10 10 OK
bigDiff([2, 3]) → 1 3 X
bigDiff([2, 2]) → 0 2 X
bigDiff([2]) → 0 2 X
bigDiff([5, 1, 6, 1, 9, 9]) → 8 9 X
bigDiff([7, 6, 8, 5]) → 3 8 X
bigDiff([7, 7, 6, 8, 5, 5, 6]) → 3 8 X
other tests
X
public int bigDiff(int[] nums) {
int large=0;
int small=0;
int largest=0;
int smallest=0;
int result=0;
int len=nums.length;
for(int i=0;i<len-1;i++){
large= Math.max(nums[i], nums[i+1]);
//large=n;
// if(large>largest){
//result=l
}
for(int i=0;i<len-1;i++){
small= Math.min(nums[i], nums[i+1]);
// small=n;
}
return (large-small);
}
Expected Run
bigDiff([10, 3, 5, 6]) → 7 1 X
bigDiff([7, 2, 10, 9]) → 8 1 X
bigDiff([2, 10, 7, 2]) → 8 5 X
bigDiff([2, 10]) → 8 8 OK
bigDiff([10, 2]) → 8 8 OK
bigDiff([10, 0]) → 10 10 OK
bigDiff([2, 3]) → 1 1 OK
bigDiff([2, 2]) → 0 0 OK
bigDiff([2]) → 0 0 OK
bigDiff([5, 1, 6, 1, 9, 9]) → 8 0 X
bigDiff([7, 6, 8, 5]) → 3 3 OK
bigDiff([7, 7, 6, 8, 5, 5, 6]) → 3 1 X
other tests
X
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Android studio getdrawable(int) is deprecated | 4 | 86 | |
servlet example | 11 | 40 | |
sp_configure 'external scripts enabled', 1; | 7 | 52 | |
How to execute a Python program and gather return output in Java | 2 | 31 |
Join the community of 500,000 technology professionals and ask your questions.