[Solved] What would be the most efficient way to find if a number n contains a specific number k?


If finding a count of how many times a specific digit appears in a number is what you mean, than the complexity will be O(n) where n is the length of the string (number):

char x = '7';
std::string number("9876541231654810654984431");
int count = 0;
for (size_t i = 0; i < number.size(); ++i)
    if (number[i] == x) count++;

2

solved What would be the most efficient way to find if a number n contains a specific number k?