mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-06 23:28:29 +08:00
new:新增Cangjie题解:最长重复子数组
This commit is contained in:
@ -581,6 +581,24 @@ int findLength(int* nums1, int nums1Size, int* nums2, int nums2Size) {
|
||||
}
|
||||
```
|
||||
|
||||
### Cangjie
|
||||
```cangjie
|
||||
func findLength(nums1: Array<Int64>, nums2: Array<Int64>): 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
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
<p align="center">
|
||||
|
Reference in New Issue
Block a user