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;
}