我试图移除长度为
例如,
“i sat down to write an article an article this morning but found that i i could make no progress”
将变成
“i sat down to write an article this morning but found that i could make no progress”。
我如何实现这一点? 我可以通过以下方法实现删除长度为
k
的重复相邻子字符串,其中k
指的是单词数量。代码应该以递归方式开始,从到。例如,
“i sat down to write an article an article this morning but found that i i could make no progress”
将变成
“i sat down to write an article this morning but found that i could make no progress”。
我如何实现这一点? 我可以通过以下方法实现删除长度为
1
的相邻子字符串:str.chunk{|n| n}.map(&:first)
k
应该是11。要移除子字符串“i”,k
应该是2。那么,移除它们的逻辑是什么呢? - sawa