15% off all plans & roadmaps Use code
See plansLeetCode 13 · Solution & editorial
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
Roman to Integer is a String Manipulation Patterns problem, in the Integer and Roman Conversion subpattern. The pattern covers palindrome checking, anagram detection, pattern matching, and string conversion
Learn to convert between integers and Roman numerals. Essential string manipulation problem.
The reference solution runs in O(n) time and O(1) space.
Roman to Integer has been reported in interviews at Amazon, Roblox, Microsoft, Adobe, Facebook, LinkedIn, Google, Apple.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Roman to Integer is a String Manipulation Patterns problem, in the Integer and Roman Conversion subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.