We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2d6485c commit fb85996Copy full SHA for fb85996
missing-number/HC-kang.ts
@@ -1,3 +1,10 @@
1
+/**
2
+ * https://leetcode.com/problems/missing-number/
3
+ * T.C.: O(n)
4
+ * S.C.: O(1)
5
+ */
6
function missingNumber(nums: number[]): number {
- return 0;
7
+ let sum = nums.length; // i for 0 to n-1. So, n is missing.
8
+ for (let i = 0; i < nums.length; i++) sum = sum + i - nums[i];
9
+ return sum;
10
}
0 commit comments