受到这个朴素的StackOverflow问题的启发。
这个想法很简单;给定一个String和一个String数组,请从输入String中移除除第一个字符串之外的所有单词实例(忽略大小写),以及可能会留下的其他空白。单词必须匹配输入字符串中的整个单词,而不是单词的一部分。
例如 "A cat called matt sat on a mat and wore a hat A cat called matt sat on a mat and wore a hat", ["cat", "mat"]
应该输出"A cat called matt sat on a mat and wore a hat A called matt sat on a and wore a hat"
输入项
- 输入可以作为字符串,也可以作为字符串数组或字符串数组,其中输入字符串是第一个元素。这些参数可以采用任何顺序。
- 输入的String不能视为空格分隔的String的列表。
- 输入的字符串将没有前导,尾随或连续空格。
- 所有输入将仅包含字符[A-Za-z0-9],但输入字符串还包括空格。
- 输入数组可能为空,或包含输入字符串中未包含的单词。
输出量
- 输出可以是函数的返回值,也可以打印到STDOUT
- 输出必须与原始String大小写相同
测试用例
the blue frog lived in a blue house, [blue] -> the blue frog lived in a house
he liked to read but was filled with dread wherever he would tread while he read, [read] -> he liked to read but was filled with dread wherever he would tread while he
this sentence has no matches, [ten, cheese] -> this sentence has no matches
this one will also stay intact, [] -> this one will also stay intact
All the faith he had had had had no effect on the outcome of his life, [had] -> All the faith he had no effect on the outcome of his life
5 times 5 is 25, [5, 6] -> 5 times is 25
Case for different case, [case] -> Case for different
the letters in the array are in a different case, [In] -> the letters in the array are a different case
This is a test Will this be correct Both will be removed, [this,will] -> This is a test Will be correct Both be removed
由于这是代码高尔夫球,因此最低字节数将获胜!
This is a test Will this be correct Both will be removed
+ 失败this will
。后两个单词已正确删除,但由于某种原因,它也删除了be
后两个单词will
。