problem0013

package
v0.0.0-...-db5e768 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2019 License: MIT Imports: 0 Imported by: 0

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. 否则,总体加上当前字符代表的数字。

总结

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

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL