描述 Enter two strings and delete all characters in the second string from the first string
字符串长度:[1, 10^5]
Example 1:
Input: str=”They are students”,sub=”aeiou”
Output: ”Thy r stdnts”
class Solution {
public:
/**
* @param str: The first string given
* @param sub: The given second string
* @return: Returns the deleted string
*/
string CharacterDeletion(string &str, string &sub) {
// write your code here
unordered_set<char> s(sub.begin(), sub.end());
string ans;
for(char c : str)
{
if(!s.count(c))
ans += c;
}
return ans;
}
};
50ms C++