更新于 2020 年 12 月 2 日 05:05:09
202 次浏览
假设我们有两个字符串 source 和 target,我们需要找到可以形成的 source 的最小子序列数,以便如果我们将它们连接起来,它将与 target 相同。如果没有这样的结果,则返回 -1。因此,如果输入类似于 source = "xyz" target = "xyzyzz",则输出将为 3,因为我们可以连接这些 ["xyz" + "yz" + "z"]要解决此问题,我们将遵循以下步骤 -s_size := s 的大小,t_size := t 的大小concat_count := 0,target_idx := 0当 target_idx < t_size 时,执行以下操作:source_idx := 0temp_index := target_idx当 source_idx ... 阅读更多