package
0.0.0-20210525112244-a601ee6fe7cf
Repository: https://github.com/smartsyoung/leetcode-in-go.git
Documentation: pkg.go.dev

# README

13. Roman to Integer

题目

Given a roman numeral, convert it to an integer.

Input is guaranteed to be within the range from 1 to 3999.

解题思路

这一题是12. Integer to Roman的一个逆转换。一样的解题思路

此题,最关键的信息是

右加左减,左减数字必须为一位,比如8写成VIII,而非IIX。

解题思路

  1. 从右往左处理字符串。
  2. 当前字符代表的数字,小于右边字符的时候,总体减去当前字符代表的数字。
  3. 否则,总体加上当前字符代表的数字。

总结

抓住关键信息,避免思维定式。