Description
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.
My
1 | class Solution: |
Best
1 | d = {'M':1000, 'D':500, 'C':100, 'L':50, 'X':10, 'V':5, 'I':1} |
Analyse
倒序的优势在于我们可以直接判定是加还是减当前的数,而不需要在多读后面的数来判断。