File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 28
28
226|[ Invert Binary Tree] ( ./0226-invert-binary-tree.js ) |Easy|
29
29
263|[ Ugly Number] ( ./0263-ugly-number.js ) |Easy|
30
30
264|[ Ugly Number II] ( ./0264-ugly-number-ii.js ) |Medium|
31
+ 268|[ Missing Number] ( ./0268-missing-number.js ) |Easy|
31
32
283|[ Move Zeroes] ( ./0283-move-zeroes.js ) |Easy|
32
33
345|[ Reverse Vowels of a String] ( ./0345-reverse-vowels-of-a-string.js ) |Easy|
33
34
347|[ Top K Frequent Elements] ( ./0347-top-k-frequent-elements.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 268. Missing Number
3
+ * https://leetcode.com/problems/missing-number/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given an array `nums` containing `n` distinct numbers in the range `[0, n]`,
7
+ * return the only number in the range that is missing from the array.
8
+ *
9
+ * Follow up: Could you implement a solution using only `O(1)` extra space
10
+ * complexity and `O(n)` runtime complexity?
11
+ */
12
+
13
+ /**
14
+ * @param {number[] } nums
15
+ * @return {number }
16
+ */
17
+ var missingNumber = function ( nums ) {
18
+ let result = 0 ;
19
+
20
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
21
+ result += i + 1 - nums [ i ] ;
22
+ }
23
+
24
+ return result ;
25
+ } ;
You can’t perform that action at this time.
0 commit comments