Skip to content

Commit e97aff4

Browse files
committed
feat: 268. Missing Number
1 parent 4213391 commit e97aff4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

missing-number/gwbaik9717.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time complexity: O(n)
2+
// Space complexity: O(1)
3+
4+
/**
5+
* @param {number[]} nums
6+
* @return {number}
7+
*/
8+
var missingNumber = function (nums) {
9+
const n = nums.length;
10+
const target = (n * (n + 1)) / 2;
11+
12+
const sum = nums.reduce((a, c) => a + c, 0);
13+
14+
return target - sum;
15+
};

0 commit comments

Comments
 (0)