Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
public class Solution { public int roman2Int(char c) { switch (c) { case 'I': return 1; case 'V': return 5; case 'X': return 10; case 'L': return 50; case 'C': return 100; case 'D': return 500; case 'M': return 1000; } return 0; } public int romanToInt(String s) { if (s.length()==0) { return 0; } if (s.length()==1) { return roman2Int(s.charAt(0)); } char c = s.charAt(0); int m = roman2Int(c); int n = romanToInt(s.substring(1)); if (s.charAt(1)==c) { return m+n; } if (m>n) { return m + n; } if (m<n) { return n-m; } return 0; } }