Hi so just a disclaimer that since there’s only 5 characters in our words it’s not a huge jump in performance. But if you looked at the example code and thought “I shouldn’t have to loop through this array more than once.” You were right.
You can take advantage of hash sets, in C++ called “unordered sets” that store references to all the characters you’ve seen, and if you seen one more than once, you can return false… here’s my implementation.
unordered_set<TCHAR> HashSet;
FString LowerCaseWord = Word.ToLower();
for (int i=0; i<LowerCaseWord.Len(); i++) {
if (HashSet.find(LowerCaseWord[i])==HashSet.end()) {
HashSet.insert(LowerCaseWord[i]);
} else {
return false;
}
}
return true;
Note: you’ll have to also add
#include <unordered_set>
to get this to work, hope it helps!