File tree 1 file changed +23
-1
lines changed
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -376,10 +376,32 @@ impl Solution {
376
376
}
377
377
```
378
378
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
+
379
402
380
403
381
404
<p align="center">
382
405
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
383
406
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
384
407
</a>
385
-
You can’t perform that action at this time.
0 commit comments