131. Integer to Roman

Medium · String

Convert a positive integer to its Roman numeral representation.

Roman numerals are constructed using seven symbols: I (1), V (5), X (10), L (50), C (100), D (500), M (1000). Numbers are formed by combining these symbols, with larger values preceding smaller ones. Subtractive notation is used for certain cases: I before V or X, X before L or C, and C before D or M.

Given an integer between 1 and 3999 (inclusive), return the corresponding Roman numeral string.

Examples

Example 1
Input: 58
Output: LVIII
Explanation: 58 = 50 + 5 + 3 = L + V + III
Example 2
Input: 1994
Output: MCMXCIV
Explanation: 1994 = 1000 + 900 + 90 + 4 = M + CM + XC + IV

Constraints