Integer to Roman
MATH
STRING
HASH TABLE

Problem

Given an integer num, convert it to a Roman numeral.

Here is the Roman numerals chart for reference:

  • I 1
  • V 5
  • X 10
  • L 50
  • C 100
  • D 500
  • M 1000

In addition, the Roman numeral system has some special rules:

  1. I can be placed before V (5) and X (10) to make 4 and 9.
  2. X can be placed before L (50) and C (100) to make 40 and 90.
  3. C can be placed before D (500) and M (1000) to make 400 and 900.

Examples

integerToRoman(3) // returns "III" // 3 represents the Roman numeral III. integerToRoman(4) // returns "IV" // 4 represents the Roman numeral IV. integerToRoman(9) // returns "IX" // 9 represents the Roman numeral IX.
Loading...