File tree 2 files changed +44
-1
lines changed
2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,106 LeetCode solutions in JavaScript
1
+ # 1,107 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
842
842
1032|[ Stream of Characters] ( ./solutions/1032-stream-of-characters.js ) |Hard|
843
843
1033|[ Moving Stones Until Consecutive] ( ./solutions/1033-moving-stones-until-consecutive.js ) |Medium|
844
844
1034|[ Coloring A Border] ( ./solutions/1034-coloring-a-border.js ) |Medium|
845
+ 1035|[ Uncrossed Lines] ( ./solutions/1035-uncrossed-lines.js ) |Medium|
845
846
1037|[ Valid Boomerang] ( ./solutions/1037-valid-boomerang.js ) |Easy|
846
847
1038|[ Binary Search Tree to Greater Sum Tree] ( ./solutions/1038-binary-search-tree-to-greater-sum-tree.js ) |Medium|
847
848
1041|[ Robot Bounded In Circle] ( ./solutions/1041-robot-bounded-in-circle.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1035. Uncrossed Lines
3
+ * https://leetcode.com/problems/uncrossed-lines/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given two integer arrays nums1 and nums2. We write the integers of nums1 and nums2
7
+ * (in the order they are given) on two separate horizontal lines.
8
+ *
9
+ * We may draw connecting lines: a straight line connecting two numbers nums1[i] and nums2[j]
10
+ * such that:
11
+ * - nums1[i] == nums2[j], and
12
+ * - the line we draw does not intersect any other connecting (non-horizontal) line.
13
+ *
14
+ * Note that a connecting line cannot intersect even at the endpoints (i.e., each number can only
15
+ * belong to one connecting line).
16
+ *
17
+ * Return the maximum number of connecting lines we can draw in this way.
18
+ */
19
+
20
+ /**
21
+ * @param {number[] } nums1
22
+ * @param {number[] } nums2
23
+ * @return {number }
24
+ */
25
+ var maxUncrossedLines = function ( nums1 , nums2 ) {
26
+ const m = nums1 . length ;
27
+ const n = nums2 . length ;
28
+
29
+ const dp = new Array ( m + 1 ) . fill ( ) . map ( ( ) => new Array ( n + 1 ) . fill ( 0 ) ) ;
30
+
31
+ for ( let i = 1 ; i <= m ; i ++ ) {
32
+ for ( let j = 1 ; j <= n ; j ++ ) {
33
+ if ( nums1 [ i - 1 ] === nums2 [ j - 1 ] ) {
34
+ dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + 1 ;
35
+ } else {
36
+ dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;
37
+ }
38
+ }
39
+ }
40
+
41
+ return dp [ m ] [ n ] ;
42
+ } ;
You can’t perform that action at this time.
0 commit comments