← 返回 roblox 的题目列表Remove Prefix Strings
类型:qbank
Remove strings that are prefixes of another string, returning only the non-prefix survivors.
Examples
Example 1:
Input: words = ["ab", "abc", "abcd", "bc", "bcd", "bd"]
Output: ["ab", "bc", "bd"]
Explanation:
"abc", "abcd", "bcd" are removed because shorter strings in the array ("ab", "ab", "bc") are prefixes of them. "ab", "bc", "bd" are kept because no shorter string is a prefix.
Example 2:
Input: words = ["a", "ab", "abc"]
Output: ["a"]
Explanation:
"a" is a prefix of "ab" and "abc"; "ab" is a prefix of "abc". Only "a" survives.
Example 3:
Input: words = ["apple", "banana", "cherry"]
Output: ["apple", "banana", "cherry"]
Explanation:
None of the strings is a prefix of any other, so the array is returned unchanged.
Constraints
1 <= words.length <= 10^4
1 <= words[i].length <= 100
words[i] consists of lowercase English letters.
Original input order must be preserved in the output.
A string is not considered its own prefix — duplicates of a kept root are all kept.