Java | Leetcode Java题解之第12题整数转罗马数字
题解:
题解:
class Solution {String[] thousands = {"", "M", "MM", "MMM"};String[] hundreds = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};String[] tens = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};String[] ones = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};public String intToRoman(int num) {StringBuffer roman = new StringBuffer();roman.append(thousands[num / 1000]);roman.append(hundreds[num % 1000 / 100]);roman.append(tens[num % 100 / 10]);roman.append(ones[num % 10]);return roman.toString();}
}