about | help | code help+videos | done | prefs |
romanToInt
Given a string representing a Roman numeral, convert it to its corresponding integer value. Roman numerals use seven basic symbols: I for 1, V for 5, X for 10, L for 50, C for 100, D for 500, and M for 1000. Normally, symbols are written from largest to smallest from left to right, and their values are added. For example, II is 2, XII is 12, and XXVII is 27. However, when a smaller value appears before a larger one, the smaller is subtracted. For example, IV is 4 because I comes before V, and IX is 9. This subtraction rule applies in six specific cases: I before V or X, X before L or C, and C before D or M. You can assume the input string is a valid Roman numeral and is written using standard rules. For example, if the input is “III”, the output should be 3. If the input is “LVIII”, the output should be 58. If the input is “MCMXCIV”, the output should be 1994. The input string will be non-empty and contain only Roman numeral characters. romanToInt("III") → 3 romanToInt("LVIII") → 58 romanToInt("MCMXCIV") → 1994 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 300
Copyright Nick Parlante 2017 - privacy