DEV Community

Discussion on: LeetCode "13. Roman to Integer"

Collapse
 
orenovadia profile image
orenovadia

I am sorry to disappoint you but I don't really know how I came up with this or in what order. I have solved this question a while ago.

ROMAN_TO_DECIMAL makes sense because for each roman numeral there is one corresponding number. There is a one to one mapping between them, and dict is python's map.

I think that the bottom line is experience. The more questions you solve on leetcode, see how other people's solutions look like, you develop more intuition as to what are the data-structures and algorithms suitable for each problem.

Also, you might find these books helpful, depends on what your goals are, and how much spare time you have:

  1. Cracking the Coding Interview
  2. Elements of Programming Interviews in Python
Thread Thread
 
takakd profile image
Takahiro Kudo

Thank you for your helpful reply.

I thought that the key solved the problem is awareness of "each roman numeral there is one corresponding number".
I will continue to solve problems and gain experiences, with other people's solutions.

And thanks for introducing books!😍