Skip to content

Commit 93a24bc

Browse files
authored
Create Missing Number In Arithmetic Progression.java
1 parent 7a448d0 commit 93a24bc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int missingNumber(int[] arr) {
3+
int n = arr.length;
4+
int d = (arr[n - 1] - arr[0]) / n;
5+
for (int i = 1; i < n; i++) {
6+
if (arr[i] - arr[i - 1] != d) {
7+
return arr[i - 1] + d;
8+
}
9+
}
10+
return d;
11+
}
12+
}

0 commit comments

Comments
 (0)