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 fc04e9e commit 139761aCopy full SHA for 139761a
problems/0349.两个数组的交集.md
@@ -113,6 +113,34 @@ Python:
113
114
Go:
115
116
+javaScript:
117
+
118
+```js
119
+/**
120
+ * @param {number[]} nums1
121
+ * @param {number[]} nums2
122
+ * @return {number[]}
123
+ */
124
+var intersection = function(nums1, nums2) {
125
+ // 根据数组大小交换操作的数组
126
+ if(nums1.length < nums2.length) {
127
+ const _ = nums1;
128
+ nums1 = nums2;
129
+ nums2 = _;
130
+ }
131
+ const nums1Set = new Set(nums1);
132
+ const resSet = new Set();
133
+ // for(const n of nums2) {
134
+ // nums1Set.has(n) && resSet.add(n);
135
+ // }
136
+ // 循环 比 迭代器快
137
+ for(let i = nums2.length - 1; i >= 0; i--) {
138
+ nums1Set.has(nums2[i]) && resSet.add(nums2[i]);
139
140
+ return Array.from(resSet);
141
+};
142
+```
143
144
145
146
0 commit comments