Reputation: 1
public class Solution {
public int AddDigits(int num) {
string strNum = num.ToString();
while (strNum.Length > 1)
{
int num1 = int.Parse(strNum[0].ToString());
int num2 = int.Parse(strNum[1].ToString());
num1 += num2;
strNum = num1.ToString();
}
Console.WriteLine(strNum);
Console.ReadLine();
return int.Parse(strNum);
}
}
The following code works with any number other than zero on leetcode website compiler. When I call the function passing the value 0 into num it fails to return anything at all into the output field (basically just crashed). If I take away Console.Readline(); it works fine with 0 does anyone know why this is? it seems to be only on leetcodes compiler.
Upvotes: 0
Views: 47