File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1
- # 2,350 + LeetCode solutions in JavaScript
1
+ # 2,400 + LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1140
1140
1223|[ Dice Roll Simulation] ( ./solutions/1223-dice-roll-simulation.js ) |Hard|
1141
1141
1224|[ Maximum Equal Frequency] ( ./solutions/1224-maximum-equal-frequency.js ) |Hard|
1142
1142
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|
1143
1144
1232|[ Check If It Is a Straight Line] ( ./solutions/1232-check-if-it-is-a-straight-line.js ) |Easy|
1144
1145
1233|[ Remove Sub-Folders from the Filesystem] ( ./solutions/1233-remove-sub-folders-from-the-filesystem.js ) |Medium|
1145
1146
1234|[ Replace the Substring for Balanced String] ( ./solutions/1234-replace-the-substring-for-balanced-string.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments