Skip to content

Commit 3919851

Browse files
committed
Add solution #1228
1 parent 5d5d058 commit 3919851

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 2,350+ LeetCode solutions in JavaScript
1+
# 2,400+ LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1140,6 +1140,7 @@
11401140
1223|[Dice Roll Simulation](./solutions/1223-dice-roll-simulation.js)|Hard|
11411141
1224|[Maximum Equal Frequency](./solutions/1224-maximum-equal-frequency.js)|Hard|
11421142
1227|[Airplane Seat Assignment Probability](./solutions/1227-airplane-seat-assignment-probability.js)|Medium|
1143+
1228|[Missing Number In Arithmetic Progression](./solutions/1228-missing-number-in-arithmetic-progression.js)|Easy|
11431144
1232|[Check If It Is a Straight Line](./solutions/1232-check-if-it-is-a-straight-line.js)|Easy|
11441145
1233|[Remove Sub-Folders from the Filesystem](./solutions/1233-remove-sub-folders-from-the-filesystem.js)|Medium|
11451146
1234|[Replace the Substring for Balanced String](./solutions/1234-replace-the-substring-for-balanced-string.js)|Medium|
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 1228. Missing Number In Arithmetic Progression
3+
* https://leetcode.com/problems/missing-number-in-arithmetic-progression/
4+
* Difficulty: Easy
5+
*
6+
* In some array arr, the values were in arithmetic progression: the values
7+
* arr[i + 1] - arr[i] are all equal for every 0 <= i < arr.length - 1.
8+
*
9+
* A value from arr was removed that was not the first or last value in the array.
10+
*
11+
* Given arr, return the removed value.
12+
*/
13+
14+
/**
15+
* @param {number[]} arr
16+
* @return {number}
17+
*/
18+
var missingNumber = function(arr) {
19+
const n = arr.length;
20+
const totalDiff = arr[n - 1] - arr[0];
21+
const expectedDiff = totalDiff / n;
22+
23+
for (let i = 1; i < n; i++) {
24+
if (arr[i] - arr[i - 1] !== expectedDiff) {
25+
return arr[i - 1] + expectedDiff;
26+
}
27+
}
28+
29+
return arr[0] + expectedDiff;
30+
};

0 commit comments

Comments
 (0)