Roman To Integer (Leetcode Problem #13)
Java Solution for https://leetcode.com/problems/roman-to-integer/
Published in
3 min readSep 9, 2021
Youtube Video
If you prefer video format : https://youtu.be/BC-mHuUAaZA
Understanding Problem
- Find the enitre problem here : https://leetcode.com/problems/roman-to-integer/
- We have been given roman symbols with its value and we need to convert roman numeral to integer value.
input_x = "LVIII"
output_x = 58
L = 50; V=5; III=3
- There some facts about roman numerals. They are usually written from largest to smallest. In above example L is larger than V.
- There some instances mentioned below where subtraction is used.
- I can be placed before (V & X); X can be placed before (L & C); C can be placed before (D & M).
- So four is not written lie IIII , rather it is written as IV.
My Thought About Solution
- I can convert roman numeral string to char array.
- Since generally roman numerals are written largest to smallest usually except some cases where subtraction is needed, I can just check the case that if current char value is greater than next char value, if yes than i can…