Remove Chars from String in place
Remove given characters in input string, the relative order of other characters should be remained. Return the new string after deletion.
Assumptions
The given input string is not null.
The characters to be removed is given by another string, it is guaranteed to be not null.
Examples
input = "abcd", t = "ab", delete all instances of 'a' and 'b', the result is "cd".
Solution: HashSet and fast slow pointer
Time Comp:
O(t) convert to set.
O(traverse input) * O(1) access set
O(t + N)
Space Comp: O(t)
Last updated
Was this helpful?