Solved LeetCode program · 828 of 1,000
#1092 · Shortest Common Supersequence
Original English source
The first is "abac". The second is "cab". The awidth is the length of first. The bwidth is the length of second. The width is bwidth plus 1. The table is an empty list of whole numbers.
For every spot from 0 to (awidth plus 1) times width minus 1.
Place 0 into table.
For every band from 1 to awidth.
For every column from 1 to bwidth.
The above is item ((band minus 1) times width plus column) of table. The beside is item (band times width plus column minus 1) of table. The corner is item ((band minus 1) times width plus column minus 1) of table. The best is above. If beside is more than best, set best to beside. The aat is band minus 1. The bat is column minus 1. The firstsymbol is character aat of first. The secondsymbol is character bat of second. If firstsymbol is secondsymbol, set best to corner plus 1. Set item (band times width plus column) of table to best.
The parts is an empty list of text. The band is awidth. The column is bwidth.
Repeat while band is more than 0 and column is more than 0.
The aat is band minus 1. The bat is column minus 1. The firstsymbol is character aat of first. The secondsymbol is character bat of second. The upper is item (aat times width plus column) of table. The lower is item (band times width plus bat) of table. If firstsymbol is secondsymbol, The piece is the slice of first from aat to band, Place piece into parts, Subtract 1 from band, Subtract 1 from column. If firstsymbol is not secondsymbol and upper is at least lower, The piece is the slice of first from aat to band, Place piece into parts, Subtract 1 from band. If firstsymbol is not secondsymbol and upper is less than lower, The piece is the slice of second from bat to column, Place piece into parts, Subtract 1 from column.
Repeat while band is more than 0.
The aat is band minus 1. The piece is the slice of first from aat to band. Place piece into parts. Subtract 1 from band.
Repeat while column is more than 0.
The bat is column minus 1. The piece is the slice of second from bat to column. Place piece into parts. Subtract 1 from column.
The answer is an empty list of text. The spot is the last position of parts.
Repeat while spot is at least 0.
Place item spot of parts into answer. Subtract 1 from spot.
The line is join answer with "". Show line.
Expected stdout
cabac