Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
my answer:
public class Solution {
public String intToRoman(int num) {
String [][] Roman_table= {
{"", "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"}
};
String ret="";
int temp=0;
while(num!=0){
int remain = num%10;
ret = Roman_table[temp][remain] + ret;
num/=10;
temp++;
}
return ret;
}
}
Runtime: 12 ms