13. Roman to Integer
# Easy
Solution:
if
roman{cur} < roman{next}
, two letters must be computed together,cur
andnext
pointers are moved 2 steps.if
roman{cur} >= roman{next}
, then only collect roman{cur}, cur and next pointers are moved 1 step.Don't forget to consider one last edge situation, if
cur
points to last element, add it tonum
directly, ifcur
points out of range, ignore it.
Last updated
Was this helpful?