LeetCode 筆記 - 583. Delete Operation for Two Strings
題目在此 583. Delete Operation for Two Strings
給定兩個字串,請找出最少將它們刪成一樣字串的次數
解題思維
同學,在這裡我們會用到 Longest Common Subsequence 的概念
如果沒解過可以先看這篇 LeetCode 筆記 - 1143. Longest Common Subsequence
我們在這裡先計算出 Longest Common Subsequence 的結果
因為 Longest Common Subsequence 是不會被刪掉的
而剩下的字元都會被刪掉
所以答案就變成 size1 + size2 - 2 * lcs
程式碼
1 | class Solution: |