lc12 Integer to Roman
因为题目输入只有1~3999,只需要将所有情况列出即可
1 class Solution { 2 public String intToRoman(int num) { 3 String[] symbol = {"M", "CM", "D","CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; 4 int[] value = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; 5 StringBuilder sb = new StringBuilder(); 6 for(int i=0; i<13; i++){ 7 while(num >= value[i]){ 8 sb.append(symbol[i]); 9 num -= value[i]; 10 } 11 } 12 13 return sb.toString(); 14 } 15 }