描述
给一串名字,将他们去重之后返回。两个名字重复是说在忽略大小写的情况下是一样的。
您在真实的面试中是否遇到过这个题?
是
样例
给出:
[
"James",
"james",
"Bill Gates",
"bill Gates",
"Hello World",
"HELLO WORLD",
"Helloworld"
]
返回:
[
"james",
"bill gates",
"hello world",
"helloworld"
]
返回名字必须都是小写字母。
无难度题目
class Solution { public: /** * @param names: a string array * @return: a string array */ vector<string> nameDeduplication(vector<string> &names) { // write your code here set<string> m_set; vector<string> m_vector; for(int i=0;i<names.size();i++){ for(int j=0;j<names[i].size();j++){ if(names[i][j]-'A'>=0&&names[i][j]-'A'<26) names[i][j]=names[i][j]-'A'+'a'; } m_set.insert(names[i]); } for(auto str:m_set) m_vector.push_back(str); return m_vector; } };