File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * 718. Maximum Length of Repeated Subarray
3
+ * https://leetcode.com/problems/maximum-length-of-repeated-subarray/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given two integer arrays nums1 and nums2, return the maximum length of a subarray
7
+ * that appears in both arrays.
8
+ */
9
+
10
+ /**
11
+ * @param {number[] } nums1
12
+ * @param {number[] } nums2
13
+ * @return {number }
14
+ */
15
+ var findLength = function ( nums1 , nums2 ) {
16
+ const dp = new Array ( nums1 . length + 1 ) . fill ( ) . map ( ( ) => {
17
+ return new Array ( nums2 . length + 1 ) . fill ( 0 ) ;
18
+ } ) ;
19
+ let result = 0 ;
20
+
21
+ for ( let i = 1 ; i <= nums1 . length ; i ++ ) {
22
+ for ( let j = 1 ; j <= nums2 . length ; j ++ ) {
23
+ if ( nums1 [ i - 1 ] === nums2 [ j - 1 ] ) {
24
+ dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + 1 ;
25
+ result = Math . max ( result , dp [ i ] [ j ] ) ;
26
+ }
27
+ }
28
+ }
29
+
30
+ return result ;
31
+ } ;
Original file line number Diff line number Diff line change 542
542
714|[ Best Time to Buy and Sell Stock with Transaction Fee] ( ./0714-best-time-to-buy-and-sell-stock-with-transaction-fee.js ) |Medium|
543
543
715|[ Range Module] ( ./0715-range-module.js ) |Hard|
544
544
717|[ 1-bit and 2-bit Characters] ( ./0717-1-bit-and-2-bit-characters.js ) |Easy|
545
+ 718|[ Maximum Length of Repeated Subarray] ( ./0718-maximum-length-of-repeated-subarray.js ) |Medium|
545
546
720|[ Longest Word in Dictionary] ( ./0720-longest-word-in-dictionary.js ) |Medium|
546
547
722|[ Remove Comments] ( ./0722-remove-comments.js ) |Medium|
547
548
724|[ Find Pivot Index] ( ./0724-find-pivot-index.js ) |Easy|
You can’t perform that action at this time.
0 commit comments