bigDiff([10, 3, 5, 6]) → 7
bigDiff([7, 2, 10, 9]) → 8
bigDiff([2, 10, 7, 2]) → 8
Answer 1:
public int bigDiff(int[] nums) {
int max = nums[0];
int min = nums[0];
for(int i=0;i<nums.length;i++){
max = Math.max(max, nums[i]);
min = Math.min(min, nums[i]);
}
return max-min;
}
No comments :
Post a Comment