We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c403469 commit 92c7607Copy full SHA for 92c7607
scripts/algorithms/I/Intersection of Multiple Arrays/Intersection of Multiple Arrays.js
@@ -1,16 +1,17 @@
1
-var intersection = function(nums) {
2
- let set = addToSet(nums[0]);
+// Runtime: 111 ms (Top 46.85%) | Memory: 44.4 MB (Top 73.58%)
+var intersection = function(nums) {
3
+ let set = addToSet(nums[0]);
4
for(let i=1; i<nums.length; i++) {
5
let tempSet = addToSet(nums[i]);
- for(let key of set) {
6
- if( !tempSet.has(key) )
+ for(let key of set) {
7
+ if( !tempSet.has(key) )
8
set.delete(key);
9
}
- }
10
+ }
11
return [...set].sort( (a,b) => a-b );
12
};
13
14
function addToSet(arr) {
15
let set = new Set(arr);
16
return set;
-}
17
+}
0 commit comments