6
6
import java .util .List ;
7
7
import java .util .Map ;
8
8
9
- /**
10
- * 1228. Missing Number In Arithmetic Progression
11
- *
12
- * In some array arr, the values were in arithmetic progression: the values arr[i+1] - arr[i] are all equal for every 0 <= i < arr.length - 1.
13
- * Then, a value from arr was removed that was not the first or last value in the array.
14
- * Return the removed value.
15
- *
16
- * Example 1:
17
- * Input: arr = [5,7,11,13]
18
- * Output: 9
19
- * Explanation: The previous array was [5,7,9,11,13].
20
- *
21
- * Example 2:
22
- * Input: arr = [15,13,12]
23
- * Output: 14
24
- * Explanation: The previous array was [15,14,13,12].
25
- *
26
- * Constraints:
27
- * 3 <= arr.length <= 1000
28
- * 0 <= arr[i] <= 10^5
29
- * */
30
9
public class _1228 {
31
10
public static class Solution1 {
32
- /**A super verbose and inefficient but working way...*/
11
+ /**
12
+ * A super verbose and inefficient but working way...
13
+ */
33
14
public int missingNumber (int [] arr ) {
34
15
Arrays .sort (arr );
35
16
Map <Integer , List <Integer >> map = new HashMap <>();
@@ -50,7 +31,9 @@ public int missingNumber(int[] arr) {
50
31
}
51
32
52
33
public static class Solution2 {
53
- /**credit: https://leetcode.com/problems/missing-number-in-arithmetic-progression/discuss/408474/JavaC%2B%2BPython-Arithmetic-Sum-and-Binary-Search*/
34
+ /**
35
+ * credit: https://leetcode.com/problems/missing-number-in-arithmetic-progression/discuss/408474/JavaC%2B%2BPython-Arithmetic-Sum-and-Binary-Search
36
+ */
54
37
public int missingNumber (int [] arr ) {
55
38
int min = arr [0 ];
56
39
int max = arr [0 ];
0 commit comments