← 返回 bytedance 的题目列表Convert Between Integer and Roman (Two-Way)
类型:online_judge
Given an integer num (1 ≤ num ≤ 3999), convert it to a Roman numeral string.
Also given a valid Roman numeral string s (representing the same range), convert it to an integer.
Implement two functions:
intToRoman(num) -> string
romanToInt(s) -> int
Requirements:
Use standard Roman numeral rules (including subtractive forms like IV, IX, XL, XC, CD, CM).
The input to romanToInt is guaranteed to be a valid Roman numeral.
Constraints:
num is in 1..3999
s.length ≤ 15
Provide test cases that validate correctness (cover: min, max, multiple subtractive forms, additive-only cases).
Example
Input
intToRoman
1
Output
I