Assuming my constraints are
1<=n<=10^9
0<=k<=9
What would be the best algorithm to search this in minimum time?
I have tried 2 methods for this: My first method n is the number and k is 4 or 7
while(n>0)
{
d=n%10;
if(d==4 || d==7)
return true;
n/=10;
}
My second method im converting the number to a string and using the find function:
string str = NumberToString(i);
if ((str.find("4") != std::string::npos) || (str.find("7") != std::string::npos))
c++;
Is there another faster way to achieve this? All i need is that the number should contain 4 or 7