Checking if a list of strings can be chained

后端 未结 8 795
庸人自扰
庸人自扰 2021-01-31 23:45

Question

Implement a function bool chainable(vector v), which takes a set of strings as parameters and returns true if they

8条回答
  •  一个人的身影
    2021-02-01 00:18

    if you replace petal and lion with pawn and label, you still have:
    starts:s,p,l,n
    ends: p,l,n,k

    You're algorithm decides its chainable, but they aren't.
    The problem is you are disconnecting the first and last letters of each word.

    A recursive backtracking or dynamic programming algorithm should solve this problem.

提交回复
热议问题