LeetCode Roman to Integer

With regards to this coding puzzle: https://leetcode.com/problems/roman-to-integer/submissions/
I am stuck with the following error : `Line 26: Char 20: error CS0029: Cannot implicitly convert type 'string' to 'int' (in Solution.cs) Line 2: Char 16: error CS0161: 'Solution.RomanToInt(string)': not all code paths return a value (in Solution.cs)`

Could anyone point out what I have done wrong? Here’s my code right now:

``````public class Solution {
public int RomanToInt(string s) {

var rNmls = new string[][]{
new string[]{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},
new string[]{"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},
new string[]{"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},
new string[]{"", "M", "MM", "MMM"}
};

var dgts = s.ToString().ToCharArray();
Array.Reverse(dgts);

string rNml = "";
var i = dgts.Length;
while(i-- > 0){
rNml += rNmls[i][dgts[i]-'0'];

}

int amt;
if(int.TryParse(rNml, out amt)){
return rNml;
}
``````

Hi,
Your first error is because you’re trying to see if a string can be converted to an int. But then if it can, you’re trying to return that string.
Your second is when something fails that if statement nothing is returned, but the program is expecting an int.

1 Like

Thank you so much for your help !

1 Like

Thanks for the help.

1 Like