File tree 3 files changed +58
-0
lines changed
solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays
3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -161,6 +161,27 @@ func longestCommomSubsequence(arrays [][]int) []int {
161
161
}
162
162
```
163
163
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
+
164
185
### ** ...**
165
186
166
187
```
Original file line number Diff line number Diff line change @@ -151,6 +151,27 @@ func longestCommomSubsequence(arrays [][]int) []int {
151
151
}
152
152
```
153
153
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
+
154
175
### ** ...**
155
176
156
177
```
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments