Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char firstNotRepeatingCharacter(std::string s)
- {
- for(int searchedChar = 0; searchedChar < s.size();)
- {
- std::vector <int> duplicatePositions;
- for(int possibleDuplicate = searchedChar+1; possibleDuplicate < s.size(); possibleDuplicate++)
- {
- if(s.at(searchedChar) == s.at(possibleDuplicate))
- {
- duplicatePositions.push_back(possibleDuplicate);
- }
- }
- if(duplicatePositions.size() > 0)
- {
- for(int i = 0; i < duplicatePositions.size(); i++)
- {
- s.erase(s.begin()+(duplicatePositions.at(i)-i));
- }
- s.erase(s.begin()+searchedChar);
- }
- else
- {
- return s.at(searchedChar);
- }
- }
- return '_';
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- char firstNotRepeatingCharacter(string s) {
- int count[26] = {};
- int order[26];
- int i = 0;
- for (c : s)
- if (!count[c-'a']++)
- order[i++] = c-'a';
- for (int j = 0; j < i; ++j)
- if (count[order[j]] == 1)
- return order[j]+'a';
- return '_';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement