We write the integers of A and B (in the order they are given) on two separate horizontal lines.
Now, we may draw connecting lines: a straight line connecting two numbers A[i] and B[j] such that:
- A[i] == B[j];
- The line we draw does not intersect any other connecting (non-horizontal) line.
Note that a connecting lines cannot intersect even at the endpoints: each number can only belong to one connecting line.
Return the maximum number of connecting lines we can draw in this way.
我們在兩條不同的平行線上寫下分別(按照給定的順序)寫下數列A和B。
現在我們再加上連接線:一條直線在A[i]和B[j]上,當:
- A[i] == B[j];
- 這條線不會和其他的連接線相交。
注意,即使只有在頂點連接也算是相交,也就是說,每個數字只能被一條連接線給使用。
回傳在以上條件,我們能夠畫出的連接線可能的最大數值。
筆者:WTF 這圖也太大…
LeetCode
C++