Leetcode 583. Delete Operation for Two Strings

Input: word1 = "sea", word2 = "eat"
Output: 2
Explanation: You need one step to make "sea" to "ea" and another step to make "eat" to "ea".
Input: word1 = "leetcode", word2 = "etco"
Output: 4
  • 1 <= word1.length, word2.length <= 500
  • word1 and word2 consist of only lowercase English letters.
  1. need to find the same substring, and delete all other character
  2. using DP to track the max substring



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gary Chiang

Gary Chiang

CS new grad, 6 years experience related to supply chain management. Located in Bay area