Back to course home
0% completed
Solution: Edit Distance
Problem Statement
Given two strings word1
and word2
, return the least number of edits
needed to transform
word1
to word2
.
You can perform any one
edit from below three in a single operation
on Word:
Insert
a characterDelete
a characterReplace
a character
Examples
-
Example 1:
- Input: word1 =
"cat"
, word2 ="cut"
- Expected Output: 1
- Justification: Only one operation is needed, replacing 'a' with 'u' in "cat" to make it "cut".
- Input: word1 =
-
Example 2:
- Input: word1 =
"sun"
, word2 ="satur"
- Expected Output: 3
- Input: word1 =
.....
.....
.....
Like the course? Get enrolled and start learning!