2.3.2 Find Longest Common Suffix

定義: 找出兩個字串中最長的共同suffix

情境:

  • String 1: Cornfield, String 2: outfield

    -> LCS: field

  • String1: Manhours, String 2: manhole

    -> LCS: NULL (anho不是suffix)

這種問題基本上就是要用dynamic programming去解的, 如果以表格來分析的話大概就會長得像下面這張圖:

以下是程式的部分:

原始碼點我

測試的部分:

原始碼點我

Last updated

Was this helpful?