mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
new:新增Cangjie题解:最长公共子序列
This commit is contained in:
@ -399,6 +399,24 @@ int longestCommonSubsequence(char* text1, char* text2) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Cangjie
|
||||||
|
```cangjie
|
||||||
|
func longestCommonSubsequence(text1: String, text2: String): Int64 {
|
||||||
|
let n = text1.size
|
||||||
|
let m = text2.size
|
||||||
|
let dp = Array(n + 1, {_ => Array(m + 1, repeat: 0)})
|
||||||
|
for (i in 1..=n) {
|
||||||
|
for (j in 1..=m) {
|
||||||
|
if (text1[i - 1] == text2[j - 1]) {
|
||||||
|
dp[i][j] = dp[i - 1][j - 1] + 1
|
||||||
|
} else {
|
||||||
|
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dp[n][m]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
Reference in New Issue
Block a user