mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-12 21:50:49 +08:00
Update 0718.最长重复子数组.md
0178.最长重复子数组新增C语言实现
This commit is contained in:
@ -560,10 +560,30 @@ impl Solution {
|
||||
}
|
||||
```
|
||||
|
||||
### C:
|
||||
|
||||
```c
|
||||
int findLength(int* nums1, int nums1Size, int* nums2, int nums2Size) {
|
||||
int dp[nums1Size + 1][nums2Size + 1];
|
||||
memset(dp, 0, sizeof(dp));
|
||||
int result = 0;
|
||||
for (int i = 1; i <= nums1Size; ++i) {
|
||||
for (int j = 1; j <= nums2Size; ++j) {
|
||||
if(nums1[i - 1] == nums2[j - 1]){
|
||||
dp[i][j] = dp[i - 1][j - 1] + 1;
|
||||
}
|
||||
if(dp[i][j] > result){
|
||||
result = dp[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
<p align="center">
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||
</a>
|
||||
|
||||
|
Reference in New Issue
Block a user