-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistinctAverages.java
More file actions
36 lines (34 loc) · 913 Bytes
/
DistinctAverages.java
File metadata and controls
36 lines (34 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<<<<<<< HEAD
//2465. Number of Distinct Averages
class Solution {
public int distinctAverages(int[] nums) {
int n = nums.length;
Set<Double> averages = new HashSet<>();
Arrays.sort(nums);
int i = 0, j = n-1;
while(i<j){
Double avg = (nums[i] + nums[j]) / 2.0;
averages.add(avg);
i++;
j--;
}
return averages.size();
}
=======
//2465. Number of Distinct Averages
class Solution {
public int distinctAverages(int[] nums) {
int n = nums.length;
Set<Double> averages = new HashSet<>();
Arrays.sort(nums);
int i = 0, j = n-1;
while(i<j){
Double avg = (nums[i] + nums[j]) / 2.0;
averages.add(avg);
i++;
j--;
}
return averages.size();
}
>>>>>>> be6ce0b427078b1421d5dd74adb2300dc02daeec
}