Skip to content

Commit b8630f5

Browse files
authored
feat: add js solution to lc problem: No.1940 (#1027)
1 parent f679fb0 commit b8630f5

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,27 @@ func longestCommomSubsequence(arrays [][]int) []int {
161161
}
162162
```
163163

164+
### **JavaScript**
165+
166+
```js
167+
/**
168+
* @param {number[][]} arrays
169+
* @return {number[]}
170+
*/
171+
var longestCommonSubsequence = function (arrays) {
172+
const m = new Map();
173+
const rs = [];
174+
const len = arrays.length;
175+
for (let i = 0; i < len; i++) {
176+
for (let j = 0; j < arrays[i].length; j++) {
177+
m.set(arrays[i][j], (m.get(arrays[i][j]) || 0) + 1);
178+
if (m.get(arrays[i][j]) === len) rs.push(arrays[i][j]);
179+
}
180+
}
181+
return rs;
182+
};
183+
```
184+
164185
### **...**
165186

166187
```

solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README_EN.md

+21
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,27 @@ func longestCommomSubsequence(arrays [][]int) []int {
151151
}
152152
```
153153

154+
### **JavaScript**
155+
156+
```js
157+
/**
158+
* @param {number[][]} arrays
159+
* @return {number[]}
160+
*/
161+
var longestCommonSubsequence = function (arrays) {
162+
const m = new Map();
163+
const rs = [];
164+
const len = arrays.length;
165+
for (let i = 0; i < len; i++) {
166+
for (let j = 0; j < arrays[i].length; j++) {
167+
m.set(arrays[i][j], (m.get(arrays[i][j]) || 0) + 1);
168+
if (m.get(arrays[i][j]) === len) rs.push(arrays[i][j]);
169+
}
170+
}
171+
return rs;
172+
};
173+
```
174+
154175
### **...**
155176

156177
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number[][]} arrays
3+
* @return {number[]}
4+
*/
5+
var longestCommonSubsequence = function (arrays) {
6+
const m = new Map();
7+
const rs = [];
8+
const len = arrays.length;
9+
for (let i = 0; i < len; i++) {
10+
for (let j = 0; j < arrays[i].length; j++) {
11+
m.set(arrays[i][j], (m.get(arrays[i][j]) || 0) + 1);
12+
if (m.get(arrays[i][j]) === len) rs.push(arrays[i][j]);
13+
}
14+
}
15+
return rs;
16+
};

0 commit comments

Comments
 (0)