Can you explain how the variable number is working?
Could not get the solution right
I am facing problem in editorial only.
int strToInt(string str, int number)
{
if (str.length() == 0)
{
return number;
}
char ch = str[0];
number = number + (ch - 48) * (int)pow(10, str.length() - 1);
string ros = str.substr(1);
return strToInt(ros, number);
}
here number is 123
then first we are adding value 1 * (10^2) to number and then calling the same function of remaining string i,e 23
and then adding adding 2 * (10^1) to the number and calling it to remining string i,e 3
again adding 3 ^ (10^0) to number and call ing remaining stirng which is ‘’ string
since this is our base case we return number which is 1*10^2 + 2 * 10^1 + 3 *10^0
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.