leetcode-12. Integer to Roman(整数转换成罗马数字)
2017-06-09 22:33
701 查看
https://leetcode.com/problems/integer-to-roman/#/description
思路解析:
代码如下:
思路解析:
【罗马数字】 1~9: {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}; 10~90: {"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}; 100~900: {"C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}; 1000~3000: {"M", "MM", "MMM"}.
代码如下:
public class Solution { public String intToRoman(int num) { String result=""; String[][] roman = { {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}, {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}, {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}, {"", "M", "MM", "MMM"} }; int d=0; while(num!=0) { int temp=num%10; result=roman[d][temp]+result; d++; num/=10; } return result; } }
相关文章推荐
- [C++]LeetCode 12: Integer to Roman(将整数转换为罗马数字)
- leetCode 12.Integer to Roman (整数转罗马数字) 解题思路和方法
- LeetCode | Integer to Roman(整数转换成罗马数字)
- [LeetCode]12. Integer to Roman(整数转化为罗马数字)
- leetcode 12 Integer to Roman(整型数转换为罗马数字)
- LeetCode 12 Integer to Roman (整数转罗马数字)
- [LeetCode] Roman to Integer 罗马数字转化成整数
- (LeetCode) Roman to Integer --- 罗马数字转整数
- leetcode 12.IntegertoRoman(整形转罗马数字)
- Leetcode 12 Integer to Roman整数变罗马
- leetcode:Integer to Roman(整数转化为罗马数字)
- [LeetCode] Integer to Roman 整数转化成罗马数字
- [LeetCode] Roman to Integer 罗马数字转整数
- LeetCode 12. Integer to Roman(罗马字符转阿拉伯数字)
- LeetCode 12. Integer to Roman(阿拉伯转罗马数字)
- Leetcode 13 Roman to Integer 罗马数字转整数
- Roman to Integer---罗马数字转换为十进制整数
- LeetCode--Roman to Integer 罗马数字转化成整数
- 【LeetCode-面试算法经典-Java实现】【013-Roman to Integer (罗马数字转成整数)】
- [Leetcode] Roman to integer 罗马数字转成整数