File tree 2 files changed +41
-0
lines changed
2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * 645. Set Mismatch
3
+ * https://leetcode.com/problems/set-mismatch/
4
+ * Difficulty: Medium
5
+ *
6
+ * You have a set of integers s, which originally contains all the numbers from 1 to n.
7
+ * Unfortunately, due to some error, one of the numbers in s got duplicated to another
8
+ * number in the set, which results in repetition of one number and loss of another number.
9
+ *
10
+ * You are given an integer array nums representing the data status of this set after
11
+ * the error.
12
+ *
13
+ * Find the number that occurs twice and the number that is missing and return them in
14
+ * the form of an array.
15
+ */
16
+
17
+ /**
18
+ * @param {number[] } nums
19
+ * @return {number[] }
20
+ */
21
+ var findErrorNums = function ( nums ) {
22
+ const set = new Set ( ) ;
23
+ const result = [ ] ;
24
+
25
+ for ( const n of nums ) {
26
+ if ( set . has ( n ) ) {
27
+ result . push ( n ) ;
28
+ }
29
+ set . add ( n ) ;
30
+ }
31
+
32
+ for ( let i = nums . length ; i > 0 ; i -- ) {
33
+ if ( ! set . has ( i ) ) {
34
+ result . push ( i ) ;
35
+ break ;
36
+ }
37
+ }
38
+
39
+ return result ;
40
+ } ;
Original file line number Diff line number Diff line change 132
132
606|[ Construct String from Binary Tree] ( ./0606-construct-string-from-binary-tree.js ) |Easy|
133
133
617|[ Merge Two Binary Trees] ( ./0617-merge-two-binary-trees.js ) |Easy|
134
134
628|[ Maximum Product of Three Numbers] ( ./0628-maximum-product-of-three-numbers.js ) |Easy|
135
+ 645|[ Set Mismatch] ( ./0645-set-mismatch.js ) |Medium|
135
136
648|[ Replace Words] ( ./0648-replace-words.js ) |Medium|
136
137
653|[ Two Sum IV - Input is a BST] ( ./0653-two-sum-iv-input-is-a-bst.js ) |Easy|
137
138
686|[ Repeated String Match] ( ./0686-repeated-string-match.js ) |Easy|
You can’t perform that action at this time.
0 commit comments