Solved LeetCode program · 852 of 1,000
#1143 · Longest Common Subsequence
Original English source
The first is "abcde". The second is "ace". The firstsize is the number of characters in first. The secondsize is the number of characters in second. The width is secondsize plus 1. The size is (firstsize plus 1) times width. The lengths is a list of size zeros.
For every left from 1 to firstsize.
For every right from 1 to secondsize.
The here is left times width plus right. The same is 0. If character (left minus 1) of first is character (right minus 1) of second, set same to 1. The upper is item (left times width plus right minus width) of lengths. The western is item (left times width plus right minus 1) of lengths. The diagonal is item (left times width plus right minus width minus 1) of lengths. The best is the larger of upper and western. If same is 1, set item here of lengths to diagonal plus 1. If same is 0, set item here of lengths to best.
The answer is item (firstsize times width plus secondsize) of lengths. Show answer.
Expected stdout
3