Solved LeetCode program · 72 of 1,000
#0072 · Edit Distance
Original English source
The first is "horse". The second is "ros". The lastfirst is the last position of first. The lastsecond is the last position of second. The rows is lastfirst plus 1. The columns is lastsecond plus 1. The width is columns plus 1. The height is rows plus 1. The size is width times height. The table is a list of size zeros.
For every column from 0 to lastsecond.
Set item column of table to column.
For every row from 1 to rows.
Set item (row times width) of table to row.
For every row from 1 to rows.
For every column from 1 to columns.
The index is row times width plus column. If character (row minus 1) of first is character (column minus 1) of second, set item index of table to item (index minus width minus 1) of table. Otherwise, The removal is item (index minus width) of table, The insertion is item (index minus 1) of table, The replacement is item (index minus width minus 1) of table, The best is the smaller of removal and insertion, The final best is the smaller of best and replacement, set item index of table to final best plus 1.
The last is one less than size. Show item last of table.
Expected stdout
3