文章目录
- 1. 题目
- 2. 解题
1. 题目
描述
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”
来源:https://tianchi.aliyun.com/oj/141754208384739500/160296091929219251
2. 解题
- 哈希查找
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 hereunordered_set<char> s(sub.begin(), sub.end());string ans;for(char c : str){if(!s.count(c))ans += c;}return ans;}
};
50ms C++
我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号(Michael阿明),一起加油、一起学习进步!