Notes

Personal notes on various topics

View on GitHub

Integer to Roman

Problem Description

Given an integer num where $1 \leq \text{num} \leq 3999$, convert it to its Roman numeral representation.

Roman Numeral Symbols

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

Conversion Rules

Return

Return the Roman numeral string corresponding to num.

Examples

Example 1

Input: num = 3749
Output: "MMMDCCXLIX"
Explanation:
- 3000 → MMM
- 700 → DCC
- 40 → XL
- 9 → IX

Example 2

Input: num = 58
Output: "LVIII"
Explanation:
- 50 → L
- 8 → VIII

Example 3

Input: num = 1994
Output: "MCMXCIV"
Explanation:
- 1000 → M
- 900 → CM
- 90 → XC
- 4 → IV

Constraints

Code Template

class Solution:
    def intToRoman(self, num: int) -> str:
        # Write your code here
        pass

Solutions

Back to Problem List Back to Categories