@kunashir:
I think ChrisW67 is right:
#include <QDebug>
#include <QRegExp>
int main(int argc, char **argv) {
qDebug() << ex.exactMatch("aaa");
return 0;
}
#include <QDebug>
#include <QRegExp>
int main(int argc, char **argv) {
QRegExp ex("[abc]{3,}");
qDebug() << ex.exactMatch("aaa");
return 0;
}
To copy to clipboard, switch view to plain text mode
prints 'true'.
Another algorithm I can think of, is to use O( n log(n) ) sorting method, eg. merge sort, something like:
bool isAnagram(baseWord, toTest){
if( baseWord.length() == toTest.length() ){
return sort(baseWord) == sort(toTest);
}
return false;
}
bool isAnagram(baseWord, toTest){
if( baseWord.length() == toTest.length() ){
return sort(baseWord) == sort(toTest);
}
return false;
}
To copy to clipboard, switch view to plain text mode
Complexity of this algorithm is the same as sorting method (string equality test should be linear), so its better than my previous suggestion.
Bookmarks