Roman numerals · 罗马数字
Roman numerals
Convert a Roman numeral to an int. The symbols are I=1, V=5, X=10, L=50, C=100, D=500, M=1000. Usually you add, but when a smaller symbol sits before a larger one you subtract it: IV is 4, IX is 9, MCMXCIV is 1994. Scanning from right to left makes the subtract rule easy — subtract any symbol smaller than the one to its right.
罗马数字
把罗马数字转换成 int。符号是 I=1、V=5、X=10、L=50、C=100、D=500、M=1000。通常是相加,但当较小的符号位于较大符号之前时要相减:IV 是 4,IX 是 9,MCMXCIV 是 1994。从右向左扫描能让相减规则变简单 —— 任何比它右边小的符号就相减。
Complete romanToInt(String s) converting a Roman numeral to an int. A smaller symbol before a larger one is subtracted, so IV is 4 and MCMXCIV is 1994. Assume valid input. · 完成 romanToInt(String s),把罗马数字转换成 int。较小的符号在较大符号之前表示相减,所以 IV 是 4,MCMXCIV 是 1994。假设输入合法。
Click Run to see the output here. · 点击“运行”查看此处输出。