Title Description:
Given an integer, convert it to a Roman numeral.
Input is guaranteed to being within the range from 1 to 3999.
Problem Solving Ideas:
Note that the use case is relatively small, so the use of space-time-based method, all the results are listed, and then combine the input value of the string of N.
Specific code:
1 Public classSolution {2 Public StaticString Inttoroman (intnum) {3String[][] Array={4{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},//0-95{"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},//10-906{"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},//100-9007{"", "M", "MM", "MMM"}//1000-30008 };9StringBuilder SB =NewStringBuilder ();Ten intn=num/1000; OneSb.append (array[3][n]); Anum=num%1000; - -n=num/100; theSb.append (array[2][n]); -num=num%100; - -N=num/10; +Sb.append (array[1][n]); -Num=num%10; + ASb.append (array[0][num]); at - returnsb.tostring (); - } -}
"Leetcode" 12. Integer to Roman