hoonji
BAN USERint fibDigit(int order) {
if (order == 0) {
return 0;
} else if (order == 1) {
return 1;
} else {
return fibDigit(order - 1) + fibDigit(order - 2);
}
}
void Outputpairs(int nPairs) {
for(int i = 1; i <= nPairs; i++) {
cout << "[";
cout << fibDigit(i) % 10 << ",";
cout << fibDigit(i + 1) % 10;
cout << "] ";
}
}
- hoonji April 26, 2015Using C++ set
//if any anagram of s1 is a substr of s2
bool anagram(string s1, string s2) {
set<char> contained;
for (int i = 0; i< s1.length(); i++) {
contained.insert(s1[i]);
}
for (int j = 0; j < s2.length(); j++) {
if(contained.find(s2[j]) != contained.end()) {
contained.erase(s2[j]);
}
if (contained.empty()) return true;
}
return false;
}
C++ solution. I know C++ is horrible with arrays, thus the messy handling of setting the unnecessary space to default values, and having to pass in a size, etc.
O(n)
- hoonji June 11, 2015