1
/** https://leetcode.com/problems/uncrossed-lines/2
* @param {number[]} nums13
* @param {number[]} nums26
var maxUncrossedLines = function (nums1, nums2) {7
// Array to hold the combination of connected numbers10
// We look up the connected numbers with matrix11
for (let i = 0; i < nums1.length; i++) {12
for (let j = 0; j < nums2.length; j++) {13
if (nums1[i] === nums2[j]) {19
// Only 0 or 1 connected numbers found, return24
// Array to count how many connected numbers in the matrix without crossing25
let count = Array(dp.length).fill(1);28
// Count from the last connected numbers, for each connected number, count how many other connected numbers in front of it that will not crossed with current29
for (let i = dp.length - 2; i >= 0; i--) {30
for (let j = i + 1; j < dp.length; j++) {31
if (dp[i][0] < dp[j][0] && dp[i][1] < dp[j][1]) {32
count[i] = Math.max(count[i], count[j] + 1);33
out = Math.max(out, count[i]);