I was expecting 3 when entering III but I keep on getting 1 and the funny thing is i think it is only happening with a combination of the same roman letters because II is giving me back 2 like i wanted LVIII is giving me 56 instead of 58, but MCMXCIV is giving me back 1994.
public class Solution
{
public int RomanToInt(string s)
{
if (s.Length == 1)
{
if (s == "I")
{
return 1;
}
else if (s == "V")
{
return 5;
}
else if (s == "X")
{
return 10;
}
else if (s == "L")
{
return 50;
}
else if (s == "C")
{
return 100;
}
else if(s == "D")
{
return 500;
}
else
{
return 1000;
}
}
else if (s.Length > 0 )
{
if (RomanToInt(s[0].ToString()) < RomanToInt(s.Substring(1, s.Length - 1).ToString()))
{
return RomanToInt(s.Substring(1, s.Length -1).ToString()) - RomanToInt(s[0].ToString());
}
else
{
return (RomanToInt(s[0].ToString())) + RomanToInt(s.Substring(1, s.Length - 1).ToString());
}
}
else
{
return 0;
}
}
}