(来自力扣算法第13题)
罗马数字包含以下七种字符: I
, V
, X
, L
,C
,D
和 M。
class Solution {
//把罗马数字存入map表中
Map<Character, Integer> romanValue = new HashMap<Character, Integer>() {
{
put('I', 1);
put('V', 5);
put('X', 10);
put('L', 50);
put('C', 100);
put('D', 500);
put('M', 1000);
}};
public int romanToInt(String s) {
int num=0; //用来存储罗马数字
int n=s.length();