## EvanJames的专栏

Be Real. Be Yourself.

# [LeetCode][Java] Integer to Roman

## 题目：

Given an integer, convert it to a roman numeral.

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

## 算法分析：

参考了博客http://www.cnblogs.com/springfor/p/3886459.html

* 对老中来说，不熟悉罗马数字的规律是个问题。其实就是那么几个符号，然后规律就是 1,4,5,9,10 然后每次十倍循环。
* 算法就是给一个数，大于1000的时候就写上一个M, 还大于1000，再写一个M… 终于小于1000了，看看大于900不？，大于500不…如此类推。
* 罗马数字为以下表示形式：
I 1
V 5
X 10
L 50
C 100
D 500
M 1,000

## AC代码：

public class Solution
{
public String intToRoman(int num)
{
String str = "";
String [] symbol = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
int [] value = {1000,900,500,400, 100, 90,  50, 40,  10, 9,   5,  4,   1};
for(int i=0;num!=0;i++)
{
while(num >= value[i])
{
num -= value[i];
str += symbol[i];
}
}
return str;
}
}

#### leetcode-java-13. Roman to Integer

2016-06-02 17:09:11

#### 【LeetCode】Integer to Roman 和 Roman to Integer 解题报告

2014-10-10 20:28:24

#### Integer to Roman （罗马数字转换） 【leetcode】

2013-09-20 16:09:30

#### [LeetCode]Roman to Integer,解题报告

2013-12-01 20:46:29

#### LeetCode 12 -Integer to Roman ( JAVA )

2016-04-10 20:20:20

#### (Java)LeetCode-13. Roman to Integer

2016-05-10 23:27:14

#### leetcode第13题——*Roman to Integer

2016-01-06 22:51:52

#### [LeetCode] 013. Roman to Integer (Easy) (C++/Java/Python)

2015-03-02 23:19:35

#### LeetCode --- 12. Integer to Roman

2015-01-29 10:49:53

#### 【LeetCode013算法/编程练习C++】Roman to Integer //难得击败了80%的人

2016-12-29 19:37:13