LeetCode 12 Integer to Roman (整数转罗马数字)
2017-03-03 21:45
603 查看
题目链接: https://leetcode.com/problems/integer-to-roman/?tab=Description
String M[] = {"", "M", "MM", "MMM”};//1000~3000
String C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM”};//100~900
String X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC”};//10~90
String I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX”};//1~9
按照上述对应规则可以进行选择合适的罗马数字。
参考代码:
String M[] = {"", "M", "MM", "MMM”};//1000~3000
String C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM”};//100~900
String X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC”};//10~90
String I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX”};//1~9
按照上述对应规则可以进行选择合适的罗马数字。
参考代码:
package leetcode_50; /*** * * @author pengfei_zheng * 整数转为罗马数字 */ public class Solution12 { public static String intToRoman(int num) { /*** * 对应规则如下所示: */ String M[] = {"", "M", "MM", "MMM"}; String C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}; String X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}; String I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}; return M[num/1000] + C[(num%1000)/100] + X[(num%100)/10] + I[num%10]; } }
相关文章推荐
- leetcode-12. Integer to Roman(整数转换成罗马数字)
- leetCode 12.Integer to Roman (整数转罗马数字) 解题思路和方法
- [C++]LeetCode 12: Integer to Roman(将整数转换为罗马数字)
- [LeetCode]12. Integer to Roman(整数转化为罗马数字)
- [LeetCode] Roman to Integer 罗马数字转化成整数
- (LeetCode) Roman to Integer --- 罗马数字转整数
- Leetcode 12 Integer to Roman整数变罗马
- [LeetCode] Integer to Roman 整数转化成罗马数字
- 【LeetCode-面试算法经典-Java实现】【013-Roman to Integer (罗马数字转成整数)】
- leetcode 12.IntegertoRoman(整形转罗马数字)
- LeetCode 12. Integer to Roman(阿拉伯转罗马数字)
- leetcode:Integer to Roman(整数转化为罗马数字)
- [Leetcode] Roman to integer 罗马数字转成整数
- Leetcode 13 Roman to Integer 罗马数字转整数
- leetcode 12 Integer to Roman(整型数转换为罗马数字)
- Leet Code 12 Integer to Roman - 整数转成罗马数字 - Java
- LeetCode--Roman to Integer 罗马数字转化成整数
- [LeetCode] Roman to Integer 罗马数字转整数
- LeetCode 12. Integer to Roman(罗马字符转阿拉伯数字)
- LeetCode | Integer to Roman(整数转换成罗马数字)