From 60f34628ebadd556d639ae3792af98df65c3476a Mon Sep 17 00:00:00 2001 From: Chemxy Date: Fri, 13 Sep 2024 20:42:36 +0800 Subject: [PATCH] =?UTF-8?q?new=EF=BC=9A=E6=96=B0=E5=A2=9ECangjie=E9=A2=98?= =?UTF-8?q?=E8=A7=A3=EF=BC=9A=E6=9C=80=E9=95=BF=E9=87=8D=E5=A4=8D=E5=AD=90?= =?UTF-8?q?=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0718.最长重复子数组.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/problems/0718.最长重复子数组.md b/problems/0718.最长重复子数组.md index 6c8e7101..19520d13 100644 --- a/problems/0718.最长重复子数组.md +++ b/problems/0718.最长重复子数组.md @@ -581,6 +581,24 @@ int findLength(int* nums1, int nums1Size, int* nums2, int nums2Size) { } ``` +### Cangjie +```cangjie +func findLength(nums1: Array, nums2: Array): Int64 { + let n = nums1.size + let m = nums2.size + let dp = Array(n + 1, {_ => Array(m + 1, item: 0)}) + var res = 0 + for (i in 1..=n) { + for (j in 1..=m) { + if (nums1[i - 1] == nums2[j - 1]) { + dp[i][j] = dp[i - 1][j - 1] + 1 + } + res = max(res, dp[i][j]) + } + } + return res +} +```