Skip to content

Commit fac6899

Browse files
committed
Update 1143.最长公共子序列.md
1143.最长公共子序列新增C语言实现
1 parent 00a5515 commit fac6899

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

problems/1143.最长公共子序列.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,32 @@ impl Solution {
376376
}
377377
```
378378

379+
### C:
380+
381+
```c
382+
#define max(a, b) ((a) > (b) ? (a) : (b))
383+
384+
int longestCommonSubsequence(char* text1, char* text2) {
385+
int text1Len = strlen(text1);
386+
int text2Len = strlen(text2);
387+
int dp[text1Len + 1][text2Len + 1];
388+
memset(dp, 0, sizeof (dp));
389+
for (int i = 1; i <= text1Len; ++i) {
390+
for (int j = 1; j <= text2Len; ++j) {
391+
if(text1[i - 1] == text2[j - 1]){
392+
dp[i][j] = dp[i - 1][j - 1] + 1;
393+
} else{
394+
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
395+
}
396+
}
397+
}
398+
return dp[text1Len][text2Len];
399+
}
400+
```
401+
379402
380403
381404
<p align="center">
382405
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
383406
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
384407
</a>
385-

0 commit comments

Comments
 (0)