Question:
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
Hints:
Hint-1:
I - 1
V - 5
X - 10
L - 50
C - 100
D - 500
M - 1000
Hint-2:
- If I comes before V or X, subtract 1 eg: IV = 4 and IX = 9
- If X comes before L or C, subtract 10 eg: XL = 40 and XC = 90
- If C comes before D or M, subtract 100 eg: CD = 400 and CM = 900
My Answer:
|
|
I just know basic about java, so I only use sample logic.
Sorry about that.
Runtime: 300ms
Better Answers:
|
|
Runtime: 149ms
Here use map HashMap, speed up~